Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with model inheritance #27

Closed
ghost opened this issue Dec 30, 2015 · 1 comment
Closed

Problems with model inheritance #27

ghost opened this issue Dec 30, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Dec 30, 2015

django-seed seems to ignore the fields in the base model when I try to seed them. It seeds the fields on the inherited model correctly but when it tries to save the model it throws an error because the fields on the base model are not filled.

I'll take a look at this later and see if I can fix this.

It might be useful to add Proxy models to the tests as well.

@ghost
Copy link
Author

ghost commented Dec 30, 2015

It seems to go wrong on _ptr fields which should be treated as the foreign key to the parent model. I can see that model._meta.fields returns this field and that django-seed creates a formatter for this: 'device_ptr': <function ModelSeeder.build_relation..func at 0x7f1646ea8d08>.

It inserted the base models and this works without any problems:

{<class 'apps.devices.models.Device'>: [21, 22, 23, 24, 25]}

But I see an error when it starts inserting the inherited models:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/laurens/Env/seismic-data-hub/lib/python3.4/site-packages/django_seed/seeder.py", line 136, in execute
    entity = self.entities[klass].execute(using, inserted_entities)
  File "/home/laurens/Env/seismic-data-hub/lib/python3.4/site-packages/django_seed/seeder.py", line 74, in execute
    setattr(obj, field, format(inserted_entities))
AttributeError: can't set attribute

I'm not sure what the issue is here or why it can't set an attribute.

I'm using Django-Polymorphic on this project and it throws a different error (django_seed.exceptions.SeederException: Field devices.Device.polymorphic_ctype cannot be null) but this can be solved with:

{
    'polymorphic_ctype':    lambda x: ContentType.objects.get(model='Device'),
}

Apart from that my models are of the basic:

class Device(PolymorphicModel):
    model = models.CharField(max_length=200, null=True)

class TestDevice(Device):
    description = models.CharField(max_length=200)

Edit:

If I print:

print(field)
print(format(inserted_entities))

on line 71 in /site-packages/django_seed/seeder.py.

I can see that django-seed doesn't seem to understand these fields after all:

device
device_id
Autem ducimus rerum qui molestias soluta. Veniam esse distinctio ut eveniet atque et. Saepe sit nobis consectetur soluta ea autem eligendi quo.
device_ptr
Omnis harum sapiente illum. Consectetur inventore voluptas possimus labore et dolor. Sed omnis neque dolorem asperiores. Dolore facilis et ut rerum officiis quo. - Unde deserunt est do

Might be a case of just adding these new field types?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant