feat(partner): add partner to DB

This commit is contained in:
Romain J 2020-06-19 01:35:31 +02:00
parent 12a35c3fbc
commit 0fb14fff16
3 changed files with 67 additions and 1 deletions

View file

@ -1,6 +1,6 @@
from django.contrib import admin
from apps.gnous_eu.models import Service
from apps.gnous_eu.models import Service, Partner
class ServicesAdmin(admin.ModelAdmin):
@ -22,3 +22,21 @@ class ServicesAdmin(admin.ModelAdmin):
admin.site.register(Service, ServicesAdmin)
class PartnersAdmin(admin.ModelAdmin):
list_display = (
"id",
"name",
"domain_tag",
"image_tag",
"hidden",
)
fieldsets = [
("Global", {"fields": ["name", "domain", "photo"]}),
("Descriptions", {"fields": ["description", "description_en"]}),
("Misc", {"fields": ["hidden"]}),
]
admin.site.register(Partner, PartnersAdmin)

View file

@ -0,0 +1,25 @@
# Generated by Django 3.0.2 on 2020-06-18 23:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('gnous_eu', '0002_service_description_en'),
]
operations = [
migrations.CreateModel(
name='Partner',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=150)),
('description', models.TextField()),
('description_en', models.TextField(null=True)),
('photo', models.ImageField(upload_to='partner')),
('domain', models.CharField(max_length=150)),
('hidden', models.BooleanField(default=False)),
],
),
]

View file

@ -42,3 +42,26 @@ class Service(models.Model):
f'"{settings.MEDIA_URL + self.photo.name}"'
f' width="50" height="50">'
)
class Partner(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=150)
description = models.TextField()
description_en = models.TextField(null=True)
photo = models.ImageField(upload_to="partner")
domain = models.CharField(max_length=150)
hidden = models.BooleanField(default=False)
def domain_tag(self):
return mark_safe(
f'<a href="http://{self.domain}" target="_blank">{self.domain}</a>'
)
def image_tag(self):
return mark_safe(
f"<img src="
f'"{settings.MEDIA_URL + self.photo.name}"'
f' width="50" height="50">'
)