Skip to content

Commit

Permalink
rename model to UserDetail
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 12, 2023
1 parent 105f7b5 commit 7229b08
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
34 changes: 17 additions & 17 deletions users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from core.admin import admin_site
from users import constants
from users.models import AuthorDetail, User
from users.models import User, UserDetail


class RoleFilter(admin.SimpleListFilter):
Expand All @@ -25,19 +25,19 @@ def queryset(self, request, queryset):
return queryset


class HasAuthorDetailFilter(admin.SimpleListFilter):
title = "Author detail ?"
parameter_name = "has_author_detail"
class HasUserDetailFilter(admin.SimpleListFilter):
title = "User detail ?"
parameter_name = "has_user_detail"

def lookups(self, request, model_admin):
return (("Yes", "Yes"), ("No", "No"))

def queryset(self, request, queryset):
value = self.value()
if value == "Yes":
return queryset.has_author_detail()
return queryset.has_user_detail()
elif value == "No":
return queryset.filter(author_detail__isnull=True)
return queryset.filter(user_detail__isnull=True)
return queryset


Expand All @@ -52,11 +52,11 @@ class UserAdmin(UserAdmin):
"is_administrator",
"question_count",
"quiz_count",
# "has_author_detail",
# "has_user_detail",
"last_login",
"created",
]
list_filter = [RoleFilter, HasAuthorDetailFilter, "is_staff"]
list_filter = [RoleFilter, HasUserDetailFilter, "is_staff"]
search_fields = ["id", "first_name", "last_name", "email"]
ordering = ["-created"]

Expand All @@ -69,7 +69,7 @@ class UserAdmin(UserAdmin):
"last_login",
"question_count",
"quiz_count",
"has_author_detail",
"has_user_detail",
"created",
"updated",
]
Expand All @@ -92,7 +92,7 @@ class UserAdmin(UserAdmin):
"fields": (
"question_count",
"quiz_count",
"has_author_detail",
"has_user_detail",
)
},
),
Expand Down Expand Up @@ -141,14 +141,14 @@ def quiz_count(self, user):
quiz_count.short_description = "Nbr de quizs"
quiz_count.admin_order_field = "quiz_count"

def has_author_detail(self, user):
return user.has_author_detail
def has_user_detail(self, user):
return user.has_user_detail

has_author_detail.short_description = "Author detail"
has_author_detail.boolean = True
has_user_detail.short_description = "User detail"
has_user_detail.boolean = True


class AuthorDetailAdmin(admin.ModelAdmin):
class UserDetailAdmin(admin.ModelAdmin):
list_display = [
"user",
"has_image_url",
Expand Down Expand Up @@ -181,7 +181,7 @@ def get_readonly_fields(self, request, obj=None):
def has_image_url(self, instance):
return instance.has_image_url

has_image_url.short_description = "Author image"
has_image_url.short_description = "User image"
has_image_url.boolean = True

def has_short_biography(self, instance):
Expand All @@ -204,4 +204,4 @@ def has_website_url(self, instance):


admin_site.register(User, UserAdmin)
admin_site.register(AuthorDetail, AuthorDetailAdmin)
admin_site.register(UserDetail, UserDetailAdmin)
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name="AuthorDetail",
name="UserDetail",
fields=[
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
primary_key=True,
related_name="author_detail",
related_name="user_detail",
serialize=False,
to=settings.AUTH_USER_MODEL,
),
),
("image_url", models.URLField(blank=True, max_length=500, verbose_name="Author image (link)")),
("image_url", models.URLField(blank=True, max_length=500, verbose_name="User image (link)")),
("short_biography", ckeditor.fields.RichTextField(blank=True, verbose_name="Short biography")),
(
"quiz_relationship",
Expand All @@ -38,8 +38,8 @@ class Migration(migrations.Migration):
("updated", models.DateTimeField(auto_now=True, verbose_name="Last update date")),
],
options={
"verbose_name": "Author detail",
"verbose_name_plural": "Author details",
"verbose_name": "User detail",
"verbose_name_plural": "User details",
},
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
class Migration(migrations.Migration):

dependencies = [
("users", "0007_authordetail"),
("users", "0007_userdetail"),
]

operations = [
migrations.CreateModel(
name="HistoricalAuthorDetail",
name="HistoricalUserDetail",
fields=[
(
"history_changed_fields",
Expand All @@ -31,7 +31,7 @@ class Migration(migrations.Migration):
verbose_name="Changed fields",
),
),
("image_url", models.URLField(blank=True, max_length=500, verbose_name="Author image (link)")),
("image_url", models.URLField(blank=True, max_length=500, verbose_name="User image (link)")),
("short_biography", ckeditor.fields.RichTextField(blank=True, verbose_name="Short biography")),
(
"quiz_relationship",
Expand Down Expand Up @@ -72,8 +72,8 @@ class Migration(migrations.Migration):
),
],
options={
"verbose_name": "historical Author detail",
"verbose_name_plural": "historical Author details",
"verbose_name": "historical User detail",
"verbose_name_plural": "historical User details",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
Expand Down
24 changes: 12 additions & 12 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def has_public_content(self):
.filter(Q(has_public_questions=True) | Q(has_public_quizs=True))
)

def has_author_detail(self):
return self.select_related("author_detail").filter(author_detail__isnull=False)
def has_user_detail(self):
return self.select_related("user_detail").filter(user_detail__isnull=False)

def simple_search(self, value):
search_fields = ["first_name", "last_name", "email"]
Expand Down Expand Up @@ -163,8 +163,8 @@ def has_public_quiz(self):
def has_public_content(self):
return self.get_queryset().has_public_content()

def has_author_detail(self):
return self.get_queryset().has_author_detail()
def has_user_detail(self):
return self.get_queryset().has_user_detail()

def simple_search(self, value):
return self.get_queryset().simple_search(value)
Expand Down Expand Up @@ -231,8 +231,8 @@ def has_quiz(self) -> bool:
return self.quiz_count > 0

@property
def has_author_detail(self) -> bool:
return hasattr(self, "author_detail")
def has_user_detail(self) -> bool:
return hasattr(self, "user_detail")

@property
def has_role_contributor(self) -> bool:
Expand Down Expand Up @@ -290,10 +290,10 @@ def user_post_save(sender, instance, created, **kwargs):
sendinblue.add_to_contact_list(instance, list_id=settings.SIB_CONTRIBUTOR_LIST_ID)


class AuthorDetail(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True, related_name="author_detail")
class UserDetail(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True, related_name="user_detail")
image_url = models.URLField(
verbose_name=_("Author image (link)"),
verbose_name=_("User image (link)"),
max_length=500,
blank=True,
)
Expand All @@ -307,11 +307,11 @@ class AuthorDetail(models.Model):
history = HistoricalRecords(bases=[HistoryChangedFieldsAbstractModel])

class Meta:
verbose_name = _("Author detail")
verbose_name_plural = _("Author details")
verbose_name = _("User detail")
verbose_name_plural = _("User details")

def __str__(self):
return f"{self.user} >>> Author detail"
return f"{self.user} >>> User detail"

@property
def has_image_url(self) -> bool:
Expand Down

0 comments on commit 7229b08

Please sign in to comment.