Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#14943 closed (invalid)

Meta attributes for Model refused to work with Mixin.

Reported by: xuqingkuang Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi, I defined a mixin for global usage but it looks it's refused to working with unique_together meta attribute.

Code is following:

from django.db import models

class CommonModelMixin(object):
    name = models.CharField(max_length=1024)
    description = models.TextField()
    creator = models.ForeignKey('auth.User', blank=True, null=True, default=None, editable=False)
    creation_date = models.DateTimeField(auto_now_add=True)

class Data(CommonModelMixin, models.Model):
    product = models.CharField(max_length=1024)
    class Meta:
        unique_together = ('product', 'name')

class Order(CommonModelMixin, models.Model):
    is_active = models.BooleanField(default=True)
    class Meta:
        ordering = ['is_active', 'name']

But when syncdb it just report:

$ ./manager.py syncdb
Error: One or more models did not validate:
app.data: "unique_together" refers to name, a field that doesn't exist. Check your syntax.
app.order: "ordering" refers to "name", a field that doesn't exist.

I won't to inherit the mixin class from models.Model, because I have other mixins need to define, but it breaks the logical.

Any idea about it ?

Change History (2)

comment:1 by Russell Keith-Magee, 14 years ago

Resolution: invalid
Status: newclosed

Your mixin class isn't a Django model, so the metaclass handling doesn't get activated. You need to make your mixin an abstract base model.

Also - Trac shouldn't be used for 'What's wrong" queries. It's a place to log things that are clearly bugs in Django. If you're not sure if your problem is a bug in Django, or a bug in your own code, you should ask on django-users first.

comment:2 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top