django-typed-models icon indicating copy to clipboard operation
django-typed-models copied to clipboard

Typedmodel subclass has duplicate fields

Open hamishcampbell opened this issue 13 years ago • 0 comments
trafficstars

Possibly a django 1.4 problem.

E.g.

class Animal(TypeModel):
    owner = models.ForeignKey(Owner, related_name="animals")
    name = models.CharField(max_length=40)

class Cat(Animal):
    def speak(self):
        return "Meow"

class Dog(Animal):
    def speak(self):
        return "Woof"

cat = Cat(owner=owner, name='Fluffy')
cat.save()  # missing owner violates key constraints

But constructing with the superclass works:

cat = Animal(type='app.cat', owner=owner. name='Fluffy')
cat.save()  # worked

Seems to be that the class _meta.fields list contains duplicates, so the first time values are popped from kwargs, then removed on the second pass.

hamishcampbell avatar Sep 30 '12 21:09 hamishcampbell