Skip to content

Commit

Permalink
Add location admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris272 committed Sep 4, 2024
1 parent a832d3f commit fd65457
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/open_producten/locations/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .contact import ContactAdmin
from .location import LocationAdmin
from .organisation import NeighbourhoodAmin, OrganisationAdmin, OrganisationTypeAdmin

__all__ = [
"ContactAdmin",
"LocationAdmin",
"OrganisationAdmin",
"OrganisationTypeAdmin",
"NeighbourhoodAmin",
]
10 changes: 10 additions & 0 deletions src/open_producten/locations/admin/contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.contrib import admin

from ..models import Contact


@admin.register(Contact)
class ContactAdmin(admin.ModelAdmin):
list_display = ("organisation", "last_name", "first_name")
list_filter = ("organisation",)
search_fields = ("first_name", "last_name")
10 changes: 10 additions & 0 deletions src/open_producten/locations/admin/location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.contrib import admin

from ..models import Location


@admin.register(Location)
class LocationAdmin(admin.ModelAdmin):
list_display = ("name", "city", "postcode", "street", "house_number")
list_filter = ("city",)
search_fields = ("name", "city")
37 changes: 37 additions & 0 deletions src/open_producten/locations/admin/organisation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from ..models import Neighbourhood, Organisation, OrganisationType


@admin.register(Organisation)
class OrganisationAdmin(admin.ModelAdmin):
# List
list_display = ("name", "type")
list_filter = ("type__name", "city")
search_fields = ("name",)
ordering = ("name",)
prepopulated_fields = {"slug": ("name",)}

# Detail
fieldsets = (
(
None,
{"fields": ("published", "name", "slug", "type", "logo", "neighbourhood")},
),
(_("Contact"), {"fields": ("email", "phone_number")}),
(
_("Address"),
{"fields": ("street", "house_number", "postcode", "city")},
),
)


@admin.register(OrganisationType)
class OrganisationTypeAdmin(admin.ModelAdmin):
list_display = ("name",)


@admin.register(Neighbourhood)
class NeighbourhoodAmin(admin.ModelAdmin):
list_display = ("name",)
3 changes: 3 additions & 0 deletions src/open_producten/producttypes/admin/producttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class ProductTypeAdmin(admin.ModelAdmin):
"related_product_types",
"tags",
"conditions",
"organisations",
"contacts",
"locations",
)
search_fields = ("name",)
ordering = ("name",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("locations", "0001_initial"),
("producttypes", "0004_alter_priceoption_amount"),
Expand All @@ -19,7 +18,7 @@ class Migration(migrations.Migration):
help_text="The contacts responsible for the product",
related_name="products",
to="locations.contact",
verbose_name="Product contacts",
verbose_name="Contacts",
),
),
migrations.AddField(
Expand All @@ -30,7 +29,7 @@ class Migration(migrations.Migration):
help_text="Locations where the product is available at.",
related_name="products",
to="locations.location",
verbose_name="Product locations",
verbose_name="Locations",
),
),
migrations.AddField(
Expand Down
4 changes: 2 additions & 2 deletions src/open_producten/producttypes/models/producttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ class ProductType(BasePublishableModel):

contacts = models.ManyToManyField(
Contact,
verbose_name=_("Product contacts"),
verbose_name=_("Contacts"),
related_name="products",
blank=True,
help_text=_("The contacts responsible for the product"),
)

locations = models.ManyToManyField(
Location,
verbose_name=_("Product locations"),
verbose_name=_("Locations"),
related_name="products",
blank=True,
help_text=_("Locations where the product is available at."),
Expand Down

0 comments on commit fd65457

Please sign in to comment.