Mmm yes it seems you are right. But I think this is a bit confusing
thinking about object oriented programming, it is not? Then the only
way to avoid this seems to be use an abstract base class or use some
not so clean way to simulate this behavior.



On 21 Nov, 01:36, Ramiro Morales <cra...@gmail.com> wrote:
> On Sat, Nov 20, 2010 at 7:59 AM, marco.ferrag...@gmail.com
>
>
>
>
>
>
>
>
>
> <marco.ferrag...@gmail.com> wrote:
> > Hi all! I'm new to django and I'm experimenting with models but I have
> > some trouble. I've minimized my problem to this code:
>
> > class TestBase(models.Model):
> >    base = models.CharField(max_length=255)
>
> > from django.contrib import admin
> > class TestA(TestBase):
> >    testb = models.CharField(max_length=255)
>
> > admin.site.register(TestA)
>
> > class TestB(TestBase):
> >    testc = models.CharField(max_length=255)
>
> > admin.site.register(TestB)
>
> > Trying to add TestA instances from admin interface I have this error:
> > Cannot assign "''": "TestA.testb" must be a "TestB" instance.
>
> > why testb should be a TestB instance?? It's a simple field!
>
> I suspect this is because of something that is described in the MTI docs:
>
> http://docs.djangoproject.com/en/1.2/topics/db/models/#multi-table-in...
>
> Translated to you example the relevant paragraph says:
>
> "If you have a TestBase that is also a TestB, you can get from the TestBase
> object to the TestB object by using the lower-case version of the model name:
>
> >>> p = TestBase.objects.get(id=12)
>
> # If p is a TestB object, this will give the child class:>>> p.testb
>
> <TestB: ...>
>
> "
>
> The TestA model is inheriting that 'testb' accesor from TestBase to TestB
> and it is clashing with the identically named field.
>
> --
> Ramiro Morales

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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