How to create a custom form in Django Admin page, that doesn't relate to a model

32 views
Skip to first unread message

Hanh Kieu

unread,
Sep 21, 2016, 1:48:29 AM9/21/16
to Django users
I am building a dictionary translation app that translates from one language to another, and I would like for the admin to be able to enter in two words, and their associated languages, these two words would, then get stored as a translation. Currently there is no way of doing this (Inline doesn't work, I tried, maybe someone could help?) so I would like a form that isn't associated with any models. I do, however want to preform actions on the form after the user has submitted, the actions would create a translation model object. How would i go about creating an admin form that isn't associated with a model.

Here is what my models look like:

class Language(models.Model):
language_text = models.CharField(max_length=200)
def __str__(self):
return self.language_text
class Word(models.Model):
language = models.ForeignKey(Language, on_delete=models.CASCADE)
word_text = models.CharField(max_length=200)
def __str__(self):
return self.word_text
class Translation(models.Model):
#word1 belongs to one word, one word can have many translations
word1 = models.ForeignKey(Word, on_delete=models.CASCADE, related_name="Translation_word1")
#word2 belongs to another word, one word can have many translations
word2 = models.ForeignKey(Word, on_delete=models.CASCADE, related_name="Translation_word2")
Reply all
Reply to author
Forward
0 new messages