View on GitHub

reads

https://yazansneneh.github.io/reads/

Django at a glance

Design a model

from django.db import models

class Reporter(models.Model): full_name = models.CharField(max_length=70)

def __str__(self):
    return self.full_name

class Article(models.Model): pub_date = models.DateField() headline = models.CharField(max_length=200) content = models.TextField() reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE)

def __str__(self):
    return self.headline

#### installing a model
```python
$ python manage.py makemigrations
$ python manage.py migrate

the database API and how to interact with db

<QuerySet [<Reporter: John Smith>]>. # result

 6. starts with a value:
 ```python
 Reporter.objects.get(full_name__startswith='John')
  1. contains a specefic value:
     Reporter.objects.get(full_name__startswith='John')
    
  2. delete an object : objectName.delete()

dynamic admin interface

class Article(models.Model): pub_date = models.DateField() headline = models.CharField(max_length=200) content = models.TextField() reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE)

website/news/admin.py from django.contrib import admin

from . import models

admin.site.register(models.Article) # registering model to admin website

```

Design URLs

how to create urls