Esempio n. 1
0
def add_post_to_db(posts):
    category_q = Category.objects.values('name')
    categories = []
    for item in category_q:
        categories.append(item['name'])
    for post in posts:
        if post["name"] and post["image"] and post["category"] \
            and post["date"] and post["address"] \
                and post["price"] and post["description"] and post["link"]:
            e = Event()
            e.name = post["name"],
            e.image = post["image"],
            e.category = Category.objects.get(id=1),
            e.date = post["date"],
            e.address = post["address"],
            e.price = post["price"],
            e.description = post["description"],
            e.link = post["link"]
            e.save()
            print(e)