Skip to content

Commit

Permalink
♻️ move m2m field to Product model
Browse files Browse the repository at this point in the history
  • Loading branch information
annashamray committed Feb 23, 2022
1 parent bc58739 commit 5df0a3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/open_inwoner/pdc/admin/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ class ProductAdmin(ImportExportMixin, admin.ModelAdmin):
list_display = ("name", "created_on", "display_categories")
list_filter = ("categories", "tags")
date_hierarchy = "created_on"
autocomplete_fields = ("categories", "related_products", "tags", "organizations")
autocomplete_fields = (
"categories",
"related_products",
"tags",
"organizations",
"conditions",
)
search_fields = ("name",)
prepopulated_fields = {"slug": ("name",)}
ordering = ("name",)
Expand Down Expand Up @@ -120,7 +126,7 @@ class ProductLocationAdmin(GeoAdminMixin, admin.ModelAdmin):
class ProductConditionAdmin(admin.ModelAdmin):
list_display = ("name", "question", "display_products")
list_filter = ("products__name",)
autocomplete_fields = ("products",)
search_fields = ("name",)

def display_products(self, obj):
return ", ".join(p.name for p in obj.products.all())
Expand Down
13 changes: 7 additions & 6 deletions src/open_inwoner/pdc/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ class Product(models.Model):
blank=True,
help_text=_("Attribute to sync data from PDC's (like SDG)"),
)
conditions = models.ManyToManyField(
"pdc.ProductCondition",
related_name="products",
verbose_name=_("Conditions"),
blank=True,
help_text=_("Conditions applicable for the product"),
)

class Meta:
verbose_name = _("Product")
Expand Down Expand Up @@ -309,12 +316,6 @@ class ProductCondition(models.Model):
default="",
help_text=_("Rule for the automated check"),
)
products = models.ManyToManyField(
"pdc.Product",
related_name="conditions",
verbose_name=_("Products"),
help_text=_("Products for which the condition is applicable"),
)

class Meta:
verbose_name = _("Condition")
Expand Down

0 comments on commit 5df0a3b

Please sign in to comment.