Hi,

I'm generating some test data for my models.

I have Country, States and Citys, this are descending from
models.Model.

Example:

class Country(models.Model):
    name        =
models.CharField('nombre',maxlength=50,blank=False,db_index=True,unique=True)
    language    = models.CharField('lenguaje',maxlength=5,blank=False)
    zipcode     =
models.CharField('indicativo',maxlength=10,blank=False,unique=True)

    def __str__(self):
        return '%s - id: %s' % (self.name, self.id)

    class Admin:
        pass

    class Meta:
        verbose_name    = 'pais'
        verbose_name_plural = 'paises'
        db_table        = 'jhonWebCountry'
        ordering        = ['name']


Now, I have a base class:

class BaseContent(models.Model):
    createdOn   = models.DateTimeField('fecha de
creación',editable=False,auto_now_add=True)
    modifedOn   = models.DateTimeField('fecha de
modificación',editable=False,auto_now=True)
    tags        =
models.CharField('etiquetas',maxlength=300,blank=False)
    title       =
models.CharField('titulo',maxlength=50,blank=False,db_index=True)
    userId      = models.SlugField(prepopulate_from=('title',
'title'),blank=False)
    content     = models.TextField('contenido')
    author      =
models.CharField('autor',maxlength=50,blank=False,db_index=True,default='1')
    status      =
models.IntegerField('estado',default=1,choices=ESTATUS_CHOICES)

    def __str__(self):
        return '%s - Id: %s' % (self.title, self.id)

    def html(self):
        return content

    class Admin:
        pass

    class Meta:
        verbose_name    = 'contenido'
        db_table        = 'jhonWebContent'
        get_latest_by   = 'modifedOn'
        ordering        = ['title']

And in a separate module, I have:

from django.db import models
from jhonWeb.core.models import BaseContent

# Copyrigth Soluciones Vulcano Ltda www.solucionesvulcano.com
# Core: Modulo de bloging y comentarios...

""" Clase de blog o diario/bitacora """
class Blog(BaseContent):

    def get_absolute_url(self):
        return "/diario/%s/" % self.userId

    class Admin:
        pass

    class Meta:
        verbose_name    = 'diario'
        db_table        = 'jhonWebBlog'

So, I get the tables created in sqlite, I see the admin interface of
this, I have the urls settings. All fine.

So, I go to the command line:

>>blog = Blog(tags='Producto1',title='Blog1',content='Contenido Blog')
>>blog.id

Print nothing

>>blog.save()
>>blog.id
1

And I query:

>>Blog.objects.all().count()
0

or

>>blogs = Blog.objects.all()
>>blogs.count()
0

I go to the admin interface, I click on Blogs, I *SEE* the created
blog, I clik on it and get a 404 error page. I return to the command
line and try:

>>blog = Blog.objects.filter(id=1)
>>blog.id
Traceback (most recent call last):
  File "<console>", line 1, in ?
AttributeError: 'QuerySet' object has no attribute 'id'

I try with Country, State and City, both in command line and Admin
pages, and are fine...

Weird...

So, I remove the subclassing, copy the fields from BaseContent to Blog,
then recreate the database and try.

Work fine...

My project have this layout:

-root
-root\core = here BaseContent
-root\blogs = here Blog(BaseContent). I import this way: from
jhonWeb.core.models import BaseContent


blog.save()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to