Wednesday, May 29, 2013

Re: Scripts to update Django tables

Django models instances are python objects and are manipulated as such.

Lets say you had a model:

def Game(Model):
    team1 = TextField()
    team2 = TextField()
    date = DateField()
    location = TextField()

In order to create new model instances and save them to a database you would do:

import Game

game = Game()
game.team1 = "Mine"
game.team2 = "Yours"
game.date = datetime.today()
game.location = "Game Place"
game.save()

On Wednesday, May 29, 2013 9:01:00 AM UTC-5, Brian wrote:
I'm new to Django (and frameworks in general) and having an issue with a project I'm working on.  Basically, I want to scrape data from a sports league website on a regular schedule and add updated stats into my database.  All of the Django tutorials for models I've looked at seem to give me information on how to add table data manually using the manage.py shell, fixtures, or fields on an admin page, but I cannot find anything about doing this more automatically through a script.  Is there something I'm missing, or am I trying to use Django models for something they aren't meant to be used for? 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment