mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-31 01:33:56 +02:00
updated more PR feedback
This commit is contained in:
parent
08b2060f35
commit
7d38dce08c
2 changed files with 12 additions and 8 deletions
|
@ -578,24 +578,24 @@ class DomainApplication(TimeStampedModel):
|
|||
return True
|
||||
return False
|
||||
|
||||
def to_dict(instance):
|
||||
def to_dict(self):
|
||||
"""This is to process to_dict for Domain Information, making it friendly
|
||||
to "copy" it
|
||||
|
||||
More information can be found at this- (This used #5)
|
||||
https://stackoverflow.com/questions/21925671/convert-django-model-object-to-dict-with-all-of-the-fields-intact/29088221#29088221"""
|
||||
opts = instance._meta
|
||||
opts = self._meta
|
||||
data = {}
|
||||
for field in chain(opts.concrete_fields, opts.private_fields):
|
||||
if field.get_internal_type() in ("ForeignKey", "OneToOneField"):
|
||||
# get the related instance of the FK value
|
||||
fk_id = field.value_from_object(instance)
|
||||
fk_id = field.value_from_object(self)
|
||||
if fk_id:
|
||||
data[field.name] = field.related_model.objects.get(id=fk_id)
|
||||
else:
|
||||
data[field.name] = None
|
||||
else:
|
||||
data[field.name] = field.value_from_object(instance)
|
||||
data[field.name] = field.value_from_object(self)
|
||||
for field in opts.many_to_many:
|
||||
data[field.name] = field.value_from_object(instance)
|
||||
data[field.name] = field.value_from_object(self)
|
||||
return data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue