Hacker News new | ask | show | jobs
by YPCrumble 1248 days ago
What’s wrong with that?
2 comments

The official coding style guide lines already state that it should come immediately after the fields.

https://docs.djangoproject.com/en/dev/internals/contributing...

No, it doesn't. Custom manager attributes go between the two:

```

The order of model inner classes and standard methods should be as follows (noting that these are not all required):

    All database fields
    Custom manager attributes
    class Meta
    def __str__()
    def save()
    def get_absolute_url()
    Any custom methods
```

And that guideline is not really a general guideline of how to make Django projects, but contributing to Django itself. It might make sense to keep that convention for projects build in Django, but that doesn't make this a style guide for those projects.

Official Django docs do NOT say the `class Meta` comes __immediately__ after the fields.

The docs give the example (as linked by you) looking like that, but few chapters down you can find this:

The order of model inner classes and standard methods should be as follows (noting that these are not all required):

All database fields

Custom manager attributes

class Meta

...

It's a pet peeve more than anything - I just hate it when I have to scroll around to find if a class is abstract or not, our team puts it at the top so that's never an issue. Having it anywhere else means it can be any arbitrary number of lines below the class definition making it harder to find.
I’ve never worked on a Django codebase that puts Meta at the top of a model definition. Not saying that it’s the wrong hint to do, but this just feels like feigned surprise because you surely also know that it’s far from common.
It very much was feigned surprise, though I do know a few Django devs who prefer top. I've never really understood the logic for hiding it in the middle or at the bottom even though both are much more common.