First App: SentenceBuilder

136 views
Skip to first unread message

Corbin Tarrant

unread,
Apr 15, 2012, 4:03:45 PM4/15/12
to django...@googlegroups.com
Hello everyone, I'm brand new to django and would really appreciate any help getting started.

So far I have gone through the first app tutorial and am working on my first app.

I have setup the basic structure of the app and also figured out user authentication. The code is on github: https://github.com/IAmCorbin/SentenceBuilder

I want to be able to add "words" with zero or more "tags" and then build "sentences". For building the sentences I need to store each words position in that particular sentence. I have setup the database structure, but am unsure how to setup the admin interface for doing this
Right now the admin page for a sentence is: the sentence name (text input), words (which right now is a multiple select box) and the associated user for the sentence (dropdown box). I have a separate table in the DB to store the word positions for each user and sentence, but I'm not sure how to link it all together.
The admin interface for adding words and tags is fine but I need to build a different admin page for sentence. On the sentence admin page the name and associated user inputs will work just fine, but having the words as a multiple select box isn't what I need.

Here is the database structure I have right now:
class Word(models.Model):
  name = models.CharField(max_length=50)
  user = models.ForeignKey(User, related_name='+')
  def __unicode__(self):
    return self.name
    
class Tag(models.Model):
  name = models.CharField(max_length=70)
  words = models.ManyToManyField(Word, blank=True)
  user = models.ForeignKey(User, related_name='+')
  def __unicode__(self):
    return self.name
    
class Sentence(models.Model):
  name = models.CharField(max_length=70)
  words = models.ManyToManyField(Word)
  user = models.ForeignKey(User, related_name='+')
  def __unicode__(self):
    return self.name
    
class SentencePosition(models.Model):
  word = models.ForeignKey(Word)
  sentence = models.ForeignKey(Sentence)
  position = models.IntegerField()

I would like the sentence admin page to allow adding a word at a time and it needs to update the SentencePosition table whenever a word is added/updated(moved)/removed
The interface ideally would allow you to either: add a new word from the Word table,  rearrange the order of existing words, or delete a word (any of these operations would need to update the SentencePosition table for all affected words)

How could I go about doing this?
Reply all
Reply to author
Forward
0 new messages