Re: problems with model inheritance if base class is not abstract

2010-11-21 Thread Marco Ferragina
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  wrote:
> On Sat, Nov 20, 2010 at 7:59 AM, 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
>
> 
>
> "
>
> 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.



Re: problems with model inheritance if base class is not abstract

2010-11-20 Thread Joseph (Driftwood Cove Designs)
Ramiro - you made my day.  Somehow I missed this little tid bit in the
docs - what a super handy feature!! thank you.

On Nov 20, 4:36 pm, Ramiro Morales  wrote:
> On Sat, Nov 20, 2010 at 7:59 AM, 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
>
> 
>
> "
>
> 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.



Re: problems with model inheritance if base class is not abstract

2010-11-20 Thread Ramiro Morales
On Sat, Nov 20, 2010 at 7:59 AM, 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-inheritance

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


"

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.



Re: problems with model inheritance if base class is not abstract

2010-11-20 Thread Michael Sprayberry


--- On Sat, 11/20/10, marco.ferrag...@gmail.com  
wrote:


From: marco.ferrag...@gmail.com 
Subject: problems with model inheritance if base class is not abstract
To: "Django users" 
Date: Saturday, November 20, 2010, 5:59 AM


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!

If TestBase is declared as abstract using the internal Meta Class I no
more have the error. Is this a bug or there is something that I don't
understand?

Thanks in advance :)

I think your issue is in how you are registering
 
is should look like
 
admin.site.register(TestBase, TestA)
admin.site.register(TestBase, TestB)


  

-- 
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.



problems with model inheritance if base class is not abstract

2010-11-20 Thread marco.ferrag...@gmail.com
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!

If TestBase is declared as abstract using the internal Meta Class I no
more have the error. Is this a bug or there is something that I don't
understand?

Thanks in advance :)

-- 
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.