Allows you to select by name from Django User Name

Until now, when selecting an employee, the list was displayed by UserName, but this has been changed to a Japanese name.

It looks like this before the change image.png

image.png

I would like to apply it to the screens I have implemented so far. This method was taught by Qiita. That was a really big help.

I often read the article on the net that User should be made custom, but I do not understand very well ... I didn't want to have a hard time implementing the login function, so I proceeded with the user as it was, but that may have been a mistake ...

You can feel free to ask if there is a person like a master, but I also ask questions on Qiita for hours when I do not understand, and I am worried that the answer will be long when it comes to how to create a User. It's hard to hear because it's closed ...

I think this is a harmful effect of not having a master. I would like to consider applying with menta.

For the implementation method, https://qiita.com/hdj16802/questions/5567dc92502dc0c88546 It is described on this page.

Ichiyo, code

models.py



class MyUser(User):
    def __str__(self):
           return '%s %s' % (self.last_name, self.first_name)

    class Meta:
        proxy = True
class BoardModel(models.Model):
    ''''
Board model
    '''
    title = models.CharField(verbose_name='title', max_length=100, blank=False, null=False)
    shisetsu_name = models.ForeignKey(Shisetsu, verbose_name='Facility', related_name='shisetsu_name',on_delete=models.SET_NULL,blank=True, null=True)
    content = models.TextField(verbose_name='Contents',blank=True, null=True)
    author = models.ForeignKey(MyUser, on_delete=models.CASCADE, verbose_name='Contributor')
    images = models.ImageField(verbose_name='image', upload_to='', blank=True, null=True)
    good = models.IntegerField(verbose_name='Number of likes', blank=True, default=0)
    read = models.IntegerField(verbose_name='Number of readers', blank=True, default=0)
    readtext = models.CharField(verbose_name='List of readers', max_length=200,blank=True)
    create_date = models.DateTimeField(verbose_name='Registered Date', auto_now_add=True)
    create_user = models.CharField(verbose_name='Registered user', max_length=50, null=True)
    update_date = models.DateTimeField(verbose_name='Update date and time', auto_now=True)
    update_user = models.CharField(verbose_name='Update user', max_length=50, null=True)
    
    def __str__(self):
        return self.title

This is OK

Recommended Posts

Allows you to select by name from Django User Name
[Django] Pass the user instance authenticated by API to ModelSerializer
How to get a namespaced view name from a URL (path_info) in Django
Get the song name from the title of the video you tried to sing
Output user information etc. to Django log
[Django] How to get data by specifying SQL.
Pass login user information to view in Django
Extract mobile phone model name from User Agent
From 0 to Django development environment construction to basic operation
Select PDFMiner to extract text information from PDF
Sometimes you want to access View information from Serializer with DRF (Django REST Framework)
I made a system that allows you to tweet just by making a phone call
To you who are cornered by deploying Django. Django 2.2 deployment full version on Ubuntu 18.04 + Nginx