Skip to content

Commit

Permalink
refactor: Update footer models
Browse files Browse the repository at this point in the history
  • Loading branch information
HamidRezaSZ committed Dec 22, 2024
1 parent 8d1eb40 commit 5d6f762
Show file tree
Hide file tree
Showing 20 changed files with 308 additions and 189 deletions.
38 changes: 14 additions & 24 deletions accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Generated by Django 4.1.3 on 2023-05-02 05:17
# Generated by Django 4.1.3 on 2024-12-22 15:21

import accounts.utils.validators
from django.conf import settings
import django.contrib.auth.models
import django.contrib.auth.validators
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


Expand All @@ -15,8 +13,6 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
('base', '0001_initial'),
]

operations = [
Expand All @@ -38,8 +34,6 @@ class Migration(migrations.Migration):
('avatar', models.ImageField(default='', upload_to='user-avatars', verbose_name='avatar')),
('gender', models.CharField(blank=True, choices=[('Female', 'Female'), ('Male', 'Male')], default=None, max_length=10, null=True, verbose_name='gender')),
('national_id', models.CharField(blank=True, max_length=10, null=True, validators=[accounts.utils.validators.validate_national_code], verbose_name='national_id')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'User',
Expand All @@ -49,20 +43,6 @@ class Migration(migrations.Migration):
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='Profile',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('day_of_birth', models.DateField(blank=True, null=True, verbose_name='day_of_birth')),
('marital_status', models.CharField(blank=True, choices=[('Single', 'Single'), ('Married', 'Married')], max_length=10, null=True, verbose_name='marital_status')),
('city', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='base.city', verbose_name='city')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='user')),
],
options={
'verbose_name': 'Profile',
'verbose_name_plural': 'Profiles',
},
),
migrations.CreateModel(
name='Address',
fields=[
Expand All @@ -74,13 +54,23 @@ class Migration(migrations.Migration):
('email', models.EmailField(max_length=254, verbose_name='email')),
('address', models.TextField(verbose_name='address')),
('zip_code', models.CharField(max_length=30, verbose_name='zip_code')),
('description', models.TextField(verbose_name='description')),
('city', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='base.city', verbose_name='city')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='user')),
('description', models.TextField(blank=True, null=True, verbose_name='description')),
],
options={
'verbose_name': 'Address',
'verbose_name_plural': 'Addresses',
},
),
migrations.CreateModel(
name='Profile',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('day_of_birth', models.DateField(blank=True, null=True, verbose_name='day_of_birth')),
('marital_status', models.CharField(blank=True, choices=[('Single', 'Single'), ('Married', 'Married')], max_length=10, null=True, verbose_name='marital_status')),
],
options={
'verbose_name': 'Profile',
'verbose_name_plural': 'Profiles',
},
),
]
18 changes: 0 additions & 18 deletions accounts/migrations/0002_alter_address_description.py

This file was deleted.

49 changes: 49 additions & 0 deletions accounts/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 4.1.3 on 2024-12-22 15:21

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('base', '0001_initial'),
('auth', '0012_alter_user_first_name_max_length'),
('accounts', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='profile',
name='city',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='base.city', verbose_name='city'),
),
migrations.AddField(
model_name='profile',
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='user'),
),
migrations.AddField(
model_name='address',
name='city',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='base.city', verbose_name='city'),
),
migrations.AddField(
model_name='address',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='user'),
),
migrations.AddField(
model_name='user',
name='groups',
field=models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups'),
),
migrations.AddField(
model_name='user',
name='user_permissions',
field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions'),
),
]
2 changes: 1 addition & 1 deletion base/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .contact_us import ContactUsDetailAdmin, ContactUsFormAdmin
from .dynamic_text import DynamicTextAdmin
from .faq import FAQAdmin
from .footer import FooterAdmin
from .footer import FooterAdmin, FooterColumnAdmin, FooterImageAdmin
from .menu import MenuAdmin
from .object_instance import ObjectInstanceAdmin
from .page import PageAdmin
Expand Down
32 changes: 21 additions & 11 deletions base/admin/footer.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
from django.contrib import admin

from base.models import Footer
from base.admin.singleton import SingletonModelAdmin
from base.models import Footer, FooterColumn, FooterImage, FooterRow


class FooterRowInline(admin.TabularInline):
model = FooterRow
extra = 0


@admin.register(Footer)
class FooterAdmin(admin.ModelAdmin):
"""
Admin panel for footer
"""
class FooterAdmin(SingletonModelAdmin):
list_display = ("id", "text", "logo")


list_display = ("id",)
filter_horizontal = ("social_accounts", "useful_link")
@admin.register(FooterColumn)
class FooterColumnAdmin(admin.ModelAdmin):
list_display = ("id", "title", "link", "order")
list_editable = ("order",)
search_fields = ("title", "link")
inlines = (FooterRowInline,)

def has_add_permission(self, request):
if self.model.objects.exists():
return False

return super().has_add_permission(request)
@admin.register(FooterImage)
class FooterImageAdmin(admin.ModelAdmin):
list_display = ("id", "image", "link", "order")
list_editable = ("order",)
search_fields = ("link",)
Loading

0 comments on commit 5d6f762

Please sign in to comment.