﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35866	Django documentaion style guide on models is unclear what to do with any other Python dunder methods that the model class might have	Hristo Trendafilov	Hristo Trendafilov	"Following the discussion here:
[https://github.com/astral-sh/ruff/issues/13892#issuecomment-2436995567]

It turns out that the Django documentation regarding model structuring [https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/coding-style/#model-style] is unclear.

As proposed: 


{{{
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
}}}

makes understanding that any other dunder, private methods and so on should come after the methods mentioned above, 
which violates Python class best practices of structuring code in classes, where dunder methods should be on top, then constants, staticmethods,  private methods and so on...

The following code is an example:

What Python best practices suggests:

{{{
class Person(models.Model):
    name = models.CharField(xxxx)    
    
    def __repr__(self):        
        return ""something""

    def save(*args, **kwargs):
        super().save(*args, `**kwargs)
}}}

What Django documentation suggests:

{{{
class Person(models.Model):
    name = models.CharField(xxxx)
    
    # Django methods
    def save(*args, **kwargs):
        super().save(*args, `**kwargs)
    
    # Any custom methods
    def __repr__(self):        
        return ""something""    
}}}




"	Cleanup/optimization	closed	Documentation	dev	Normal	fixed		Micha Reiser	Ready for checkin	1	0	0	0	0	0
