vendredi 14 novembre 2014

Conception de base de données de Django avec intermédiaire Table - comment faire avec l'Instance ? -Débordement de pile


Using Django, I am creating a database that will keep track of unanswered posts in forum and if/what employee(operator) is assigned to that post.


Models Operator and ThreadVault are permanent while Thread is intermediate/temp.


I will be making a api call to the forums to get a list of the unanswered posts once every ten minutes. I will then check to see if the thread ID already exists in the model ThreadVault. If not, it will add it to ThreadVault. Then, I will have a temporary/intermediate table Thread that will contain the unanswered posts for the past 10 minutes. After every 10 minutes, the table Thread will clear out and refresh with a new batch of unanswered threads.


A operator/employee may or may not be assigned to the thread. To do this, I am having ThreadVault operator_user_name point to Operator model.


class Operator:
operator_ldap = models.ForeignKey(settings.AUTH_USER_MODEL,
related_name='operator_requester')
operator_irc_name = models.CharField(max_length="25")
operator_user_name = models.CharField(max_length="25")

class ThreadVault:
thread_id = models.CharField(max_length="50")
url = models.CharField(max_length="200")
operator_user_name = models.ForeignKey(Operator) ## Can be Empty

#intermediate table
#Thread model clears out once every
#10 minutes when API repopulates data
class Thread:
url = models.ForeignKey(ThreadVault)
author_username = models.CharField(max_length="50")
author_name = models.CharField(max_length="50")
thread_id = models.ForeignKey(ThreadVault)
forum_id = models.CharField(max_length="50")
subject = models.CharField(max_length="200")
reply_count = models.CharField(max_length=("3"))
latest_post_date = models.CharField(max_length=("50"))
operator_user_name = models.ForeignKey(ThreadVault) ## Can be Empty

I know at this point I am not doing this correctly. How can I do this?




This worked out perfect:


class Operator(models.Model):
operator_ldap = models.ForeignKey(settings.AUTH_USER_MODEL,
related_name='operator_requester')
operator_irc_name = models.CharField(max_length="25",
blank=True, null=True)
operator_user_name = models.CharField(max_length="25",
blank=True, null=True)

class ThreadVault(models.Model):
thread_id = models.CharField(max_length="50")
url = models.CharField(max_length="200")
operator_user_name = models.ForeignKey(Operator, blank=True, null=True) ## Can be Empty

#intermediate table
#Thread model clears out once every
#10 minutes when API repopulates data
class Thread(models.Model):
url = models.ForeignKey(ThreadVault,
related_name="url_vault")
author_username = models.CharField(max_length="50")
author_name = models.CharField(max_length="50")
thread_id = models.ForeignKey(ThreadVault,
related_name="thread_vault")
forum_id = models.CharField(max_length="50")
subject = models.CharField(max_length="200")
reply_count = models.CharField(max_length=("3"))
latest_post_date = models.CharField(max_length=("50"))
operator_user_name = models.ForeignKey(ThreadVault,
related_name="operator_user_name_vault",
blank=True, null=True) ## Can be Empty


Using Django, I am creating a database that will keep track of unanswered posts in forum and if/what employee(operator) is assigned to that post.


Models Operator and ThreadVault are permanent while Thread is intermediate/temp.


I will be making a api call to the forums to get a list of the unanswered posts once every ten minutes. I will then check to see if the thread ID already exists in the model ThreadVault. If not, it will add it to ThreadVault. Then, I will have a temporary/intermediate table Thread that will contain the unanswered posts for the past 10 minutes. After every 10 minutes, the table Thread will clear out and refresh with a new batch of unanswered threads.


A operator/employee may or may not be assigned to the thread. To do this, I am having ThreadVault operator_user_name point to Operator model.


class Operator:
operator_ldap = models.ForeignKey(settings.AUTH_USER_MODEL,
related_name='operator_requester')
operator_irc_name = models.CharField(max_length="25")
operator_user_name = models.CharField(max_length="25")

class ThreadVault:
thread_id = models.CharField(max_length="50")
url = models.CharField(max_length="200")
operator_user_name = models.ForeignKey(Operator) ## Can be Empty

#intermediate table
#Thread model clears out once every
#10 minutes when API repopulates data
class Thread:
url = models.ForeignKey(ThreadVault)
author_username = models.CharField(max_length="50")
author_name = models.CharField(max_length="50")
thread_id = models.ForeignKey(ThreadVault)
forum_id = models.CharField(max_length="50")
subject = models.CharField(max_length="200")
reply_count = models.CharField(max_length=("3"))
latest_post_date = models.CharField(max_length=("50"))
operator_user_name = models.ForeignKey(ThreadVault) ## Can be Empty

I know at this point I am not doing this correctly. How can I do this?



This worked out perfect:


class Operator(models.Model):
operator_ldap = models.ForeignKey(settings.AUTH_USER_MODEL,
related_name='operator_requester')
operator_irc_name = models.CharField(max_length="25",
blank=True, null=True)
operator_user_name = models.CharField(max_length="25",
blank=True, null=True)

class ThreadVault(models.Model):
thread_id = models.CharField(max_length="50")
url = models.CharField(max_length="200")
operator_user_name = models.ForeignKey(Operator, blank=True, null=True) ## Can be Empty

#intermediate table
#Thread model clears out once every
#10 minutes when API repopulates data
class Thread(models.Model):
url = models.ForeignKey(ThreadVault,
related_name="url_vault")
author_username = models.CharField(max_length="50")
author_name = models.CharField(max_length="50")
thread_id = models.ForeignKey(ThreadVault,
related_name="thread_vault")
forum_id = models.CharField(max_length="50")
subject = models.CharField(max_length="200")
reply_count = models.CharField(max_length=("3"))
latest_post_date = models.CharField(max_length=("50"))
operator_user_name = models.ForeignKey(ThreadVault,
related_name="operator_user_name_vault",
blank=True, null=True) ## Can be Empty

0 commentaires:

Enregistrer un commentaire