Skip to content

Commit 1a277d7

Browse files
NishaNisha
Nisha
authored and
Nisha
committed
Enhance the backend API
1 parent 01aeab2 commit 1a277d7

28 files changed

+19
-12
lines changed
119 Bytes
Binary file not shown.
123 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1.16 KB
Binary file not shown.
1.17 KB
Binary file not shown.
540 Bytes
Binary file not shown.

pythonWORLDAPI/settings.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
2727

28-
ALLOWED_HOSTS = []
28+
#For development purpose only
29+
ALLOWED_HOSTS = ['*']
2930

3031

3132
# Application definition
@@ -80,13 +81,13 @@
8081
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
8182

8283
DATABASES = {
83-
'default': {
84-
"ENGINE": "django.db.backends.postgresql_psycopg2",
85-
"NAME": "worldapi",
86-
"USER": "postgres",
87-
"PASSWORD": "localhost",
88-
"HOST": "localhost",
89-
"PORT": "5432",
84+
'default': {
85+
'ENGINE': 'django.db.backends.postgresql',
86+
'NAME': 'postgres',
87+
'USER': 'postgres',
88+
'PASSWORD': 'postgres',
89+
'HOST': 'db',
90+
'PORT': 5432,
9091
}
9192
}
9293

@@ -109,6 +110,10 @@
109110
},
110111
]
111112

113+
FIXTURE_DIRS = (
114+
'/react-django-graphQL-postgres/Fixtures/',
115+
)
116+
112117

113118
# Internationalization
114119
# https://docs.djangoproject.com/en/3.0/topics/i18n/
113 Bytes
Binary file not shown.
117 Bytes
Binary file not shown.
154 Bytes
Binary file not shown.
158 Bytes
Binary file not shown.
2.01 KB
Binary file not shown.
20 Bytes
Binary file not shown.
2.03 KB
Binary file not shown.
4.39 KB
Binary file not shown.
13 Bytes
Binary file not shown.
4.4 KB
Binary file not shown.

worldapi/migrations/0001_initial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 2.1.7 on 2020-10-07 04:01
1+
# Generated by Django 2.1.7 on 2020-10-08 21:54
22

33
from django.db import migrations, models
44
import django.db.models.deletion
@@ -51,7 +51,7 @@ class Migration(migrations.Migration):
5151
migrations.AddField(
5252
model_name='country',
5353
name='country_capital',
54-
field=models.ForeignKey(db_column='country_capital', default=None, on_delete=django.db.models.deletion.CASCADE, to='worldapi.City'),
54+
field=models.ForeignKey(db_column='country_capital', default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='worldapi.City'),
5555
),
5656
migrations.AlterUniqueTogether(
5757
name='countrylanguage',
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

worldapi/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Country(models.Model):
2222
country_localname = models.TextField(default=None)
2323
country_governmentform = models.TextField(default=None)
2424
country_headofstate = models.TextField(null=True,blank=True)
25-
country_capital = models.ForeignKey(City, on_delete=models.CASCADE,default=None,db_column='country_capital')
25+
country_capital = models.ForeignKey(City, on_delete=models.CASCADE,default=None,db_column='country_capital',null=True)
2626
country_code2 = models.CharField(max_length=2,default=None)
2727

2828

worldapi/schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CountryLanguageType(DjangoObjectType):
1616
class Meta:
1717
model = CountryLanguage
1818

19-
19+
# This class will defines get requests
2020
class Query(graphene.ObjectType):
2121
cities = graphene.List(
2222
CityType,
@@ -96,6 +96,7 @@ def resolve_countrylanguage(self, info, countrylanguage_countrycode, **kwargs):
9696

9797
return CountryLanguage.objects.all()
9898

99+
# This class will define post requests to update or add data
99100
class AddCity(graphene.Mutation):
100101
addCity = graphene.Field(CityType)
101102

@@ -129,6 +130,7 @@ def mutate(
129130

130131
return AddCity(addCity=city)
131132

133+
# This class will defines delete request
132134
class DeleteCity(graphene.Mutation):
133135
deleteCity = graphene.Field(CityType)
134136

0 commit comments

Comments
 (0)