lundi 20 avril 2015

Django DateTimeField User Input

So I'm trying to populate a model in django using a postgres (postgis) database. The problem I'm having is inputting the datetimefield. I have written a population script but every time I run it I get the error django.db.utils.IntegrityError: null value in column "pub_date" violates not-null constraint. The code below shows my model and the part of the population script that applies to the table.

The model:

class Article(models.Model):
    authors = models.ManyToManyField(Author)
    location = models.ForeignKey(Location)
    article_title = models.CharField(max_length=200, unique_for_date="pub_date")
    pub_date = models.DateTimeField('date published')
    article_keywords = ArrayField(ArrayField(models.CharField(max_length=20, blank=True), size=8), size=8,)
    title_id = models.CharField(max_length=200)
    section_id = models.CharField(max_length=200)

And the population script:

def populate():
        id = "1",
        article_title = "Obama scrambles to get sceptics in Congress to support Iran nuclear deal",
        pub_date = "2015-04-06T20:38:59Z",
        article_keywords = "{obama, iran, debate, congress, america, un, republican, democrat, nuclear, isreal}",
        title_id = "white-house-scrambles-sceptics-congress-iran-nuclear-deal",
        section_id = "us-news",
        location_id = "1"

def add_article(id, article_title, pub_date, article_keywords, title_id, section_id, location_id):
    article = Article.objects.get_or_create(article_title=article_title)[0]
    return article

if __name__ == '__main__':
    print "Starting Newsmap population script..."


I've searched around for ages but there seems to be no solution to this specific problem. Any help much appreciated!!

Aucun commentaire:

Enregistrer un commentaire