Meta class completely missing.

33 views
Skip to first unread message

Brandon

unread,
Mar 15, 2017, 2:57:49 PM3/15/17
to Django users
print Foo.Meta throws AttributeError: type object 'Foo' has no attribute 'Meta' for *some* classes.

Reproduce it by:

from django.db import models
class Foo(models.Model):
    value
= models.CharField(max_length=256,blank=True)

   
class Meta(object):
       
pass

Then makemigrations and migrate
Then print Foo.Meta

Of the 61 models currently defined in one models.py my project 25 of them do not throw an error and have a reference to a Meta class. The other 36 throw the error above.

Is this right? What is going on? Why would some models have a Meta class and others not? Actually defining a Meta class (with or without attributes) in the model seems to make zero difference.

Any help understanding this is greatly appreciated.
--Brandon

chris rose

unread,
Mar 20, 2017, 5:55:56 AM3/20/17
to Django users
hi brandon

try removing (object) from your meta class declaration

Brandon Willis

unread,
Mar 29, 2017, 10:39:12 AM3/29/17
to django...@googlegroups.com
Done. No change.

What is also very bizarre is that *not* having a Meta class would make the "Restaurant" test (tests/model_inheritance/models.py : Line 107) break badly; class Restaurant has a Meta that subclasses the Meta of class Rating. So if Meta does not exist... well you see the problem. In fact this *exact* thing occurs in my situation. 

I have a "class Case(models.Model)" with a "class Meta:" and a "class MDxCase(Case):" if I try to do "class Meta(Case.Meta):" for class MDxCase an AttributeError error is thrown "Case has no attribute 'Meta'". 

This is very very odd.
Can anyone explain this behavior or have any other ideas to try?

--Brandon

On Mon, Mar 20, 2017 at 4:55 AM, chris rose <chris.r...@gmail.com> wrote:
hi brandon

try removing (object) from your meta class declaration

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/gGfLmihCilI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/30d054d7-8150-4eeb-bc3b-cf8a762078ae%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages