On Fri, Oct 7, 2011 at 4:25 PM, Shawn Milochik <sh...@milochik.com> wrote:
> On Fri, Oct 7, 2011 at 11:15 AM, Tom Evans <tevans...@googlemail.com> wrote:
>>
>> I do this a lot, and haven't found any problems with doing so. My main
>> app has no models.py, but has models/{__init__,foo}.py, and it is
>> still found quite happily by syncdb, south, the admin interface, the
>> app template loader etc.
>>
>> Is there a concrete example of a thing that will not work with this
>> structure?
>>
>> Cheers
>>
>> Tom
>>
>>
> If that's the case then I'm wrong. I guess Django just needs to be able to
> import 'models' from the app root. I specifically remember reading that
> 'models.py must exist' whether your app has models or not, or Django won't
> consider it an 'app.' I took that literally. I didn't consider that it might
> be checking by attempting to import rather than checking for the existence
> of a certain filename, and I never tried to do it otherwise.
> Example from docs:
> https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/ (says
> models.py must exist for tests to be discovered)
> Ticket:
> https://code.djangoproject.com/ticket/4470 (seems to indicate things don't
> work properly without a single models.py file)
> Shawn
>
>

The documentation is incorrect there - the requirement is that you
have a models module in your app, which has been mistranslated into
'you must have a models.py'.

However, that ticket has reminded me of an issue that you will get -
the app_label of your models will be incorrect. I forgot to mention
that I use a base model class for all models in a subdivided app. This
base model provides the correct app_label in its Meta class (which
means if you define a Meta class on your models, then it must derive
from the base model's meta).

Eg:

  class BaseModel(Model):
      class Meta:
          abstract = True
          app_label = 'the_app_name'

  class Foo(BaseModel):
      name = models.CharField(max_length=32)

  class Bar(BaseModel):
      name = models.CharField(max_length=32)
      location = models.CharField(max_length=32)
      class Meta(BaseModel.Meta):
          unique_together = ( ('name', 'location'), )


Cheers

Tom

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