vendredi 2 septembre 2016

Is it an anti-pattern to send a request object to a model method in Django?

I am currently trying to use the fat model, thin view pattern, moving almost all the logic to model methods.

While doing it, I am constantly finding myself sending a request object from a view to a model method:

model_method(request)

and using it in the following way:

def model_method(self, request):
    user_id = request.user.id
    user_type = request.user.__class__.__name__

    ...

Is this a good idea? or should I send what I want from the request object to the method, instead of the whole object, like this:

user_id = request.user.id
user_type = request.user.__class__.__name__

model_method(user_id, user_type)

What is the correct way?

Aucun commentaire:

Enregistrer un commentaire