custom-field-list_display 1

custom-field-list_display

from django.contrib.auth.models import User
from django.db import models

class Customer(models.Model):
    ....
    @property
    def full_name(self):
        return "%s %s"%(self.user.first_name, self.user.last_name)

    def __str__(self):
        return self.full_name
Copy

Here is what the above code is Doing:
1. We’re creating a property called full_name.
2. We’re using the @property decorator to tell Python that this is a property.
3. We’re returning the first_name and last_name of the user.
4. We’re overriding the __str__ method to return the full_name.

Similar Posts