What I found useful sometimes, was to store the content_type_id of the 
object, so when I open the parent class, I can change the type to the right 
subclass.

For example:

from django.contrib.contenttypes.models import ContentType


class Parent(models.Model):
    content_type = models.ForeignKey(ContentType)

    def save(self, *args, **kwargs):
        self.content_type = ContentType.objects.get_for_model(self)
        super(Parent, self).save(*args, **kwargs)  # Call the "real" save() 
method.

    def get_real(self):
        return self.content_type.model_class().objects.get(pk=self.pk)


Can that help?


On Sunday, August 5, 2012 7:53:51 AM UTC+2, . wrote:
>
> > But assuming you just want to set up a default, and  be able to override 
> it at will, you can always do: 
> > class Foo: 
> >    def default_name(self): 
> >       return 'Foo' 
> >    name = CharField(default=default_name) 
>
> > Class Bar(Foo): 
> >    def default_name(self): 
> >      return "Bar" 
>
> This looks right but I can't check it. 
>
> There is a class (let's call it Foo) which is a subclass of User. 
> Foo has the following line in its Meta: 
> proxy = True 
>
> When I try to validate my models this error appears: 
> django.core.exceptions.FieldError: Proxy model 'Foo' contains model 
> fields. 
>
> I will get another error if I remove "proxy = True": 
>
> Error: One or more models did not validate: 
> app.foo: Accessor for field 'user_ptr' clashes with related field 
> 'User.foo'. Add a related_name argument to the definition for 
> 'user_ptr'. 
>
> I've read a doc page on inheritance but I don't know how to fix these 
> errors. 
>
>
> Thanks 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/kgTtBeGpgZgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to