Skip to content

Commit

Permalink
Implement cheese country of origin
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Oct 4, 2020
1 parent 46bcb23 commit f7ea922
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"allauth",
"allauth.account",
"allauth.socialaccount",
"django_countries" # CountryField
]

LOCAL_APPS = [
Expand Down
19 changes: 19 additions & 0 deletions everycheese/cheeses/migrations/0002_cheese_country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.1.1 on 2020-10-04 18:37

from django.db import migrations
import django_countries.fields


class Migration(migrations.Migration):

dependencies = [
('cheeses', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='cheese',
name='country',
field=django_countries.fields.CountryField(blank=True, max_length=2, verbose_name='Country of Origin'),
),
]
18 changes: 18 additions & 0 deletions everycheese/cheeses/migrations/0003_auto_20201004_1842.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.1 on 2020-10-04 18:42

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('cheeses', '0002_cheese_country'),
]

operations = [
migrations.RenameField(
model_name='cheese',
old_name='country',
new_name='country_of_origin',
),
]
3 changes: 3 additions & 0 deletions everycheese/cheeses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from autoslug import AutoSlugField
from model_utils.models import TimeStampedModel
from django_countries.fields import CountryField


class Cheese(TimeStampedModel):
Expand All @@ -26,6 +27,8 @@ class Firmness(models.TextChoices):
firmness = models.CharField("Firmness", max_length=20,
choices=Firmness.choices, default=Firmness.UNSPECIFIED)

country_of_origin = CountryField("Country of Origin", blank=True)


def __str__(self):
return self.name
1 change: 1 addition & 0 deletions everycheese/cheeses/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CheeseFactory(factory.django.DjangoModelFactory):
firmness = factory.fuzzy.FuzzyChoice(
[x[0] for x in Cheese.Firmness.choices]
)
country_of_origin = factory.Faker('country_code')

class Meta:
model = Cheese
8 changes: 6 additions & 2 deletions everycheese/templates/cheeses/cheese_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ <h2>{{ cheese.name }}</h2>
<p>Firmness: {{ cheese.get_firmness_display }}</p>
{% endif %}



{% if cheese.description %}
<p>Description: {{ cheese.description }}</p>
{% endif %}

{% if cheese.country_of_origin %}
<p>Country of Origin: {{ cheese.country_of_origin.name }}
<img src="{{ cheese.country_of_origin.flag }}" />
</p>
{% endif %}




Expand Down
2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ django-model-utils==4.0.0 # https://github.com/jazzband/django-model-utils
django-allauth==0.42.0 # https://github.com/pennersr/django-allauth
django-crispy-forms==1.9.2 # https://github.com/django-crispy-forms/django-crispy-forms
django-autoslug==1.9.8 # https://github.com/justinmayer/django-autoslug/

django-countries==6.1.3

0 comments on commit f7ea922

Please sign in to comment.