Note that there are some explanatory texts on larger screens.

plurals
  1. PODefine a create function in django
    text
    copied!<p>I'm trying to create an "administration" page where users can create a "match", giving it a name, and display a list of the matches I created to an other page. I also would like to have a "delete" button to delete a match.</p> <p>I have this model:</p> <pre><code>class Match(models.Model): teams = models.ManyToManyField(Teams) identite = models.CharField(max_length=60) teamA = models.CharField(max_length=20) teamB = models.CharField(max_length=20) info = models.CharField(max_length=500) sport = models.CharField(max_length=20) date_start = models.DateTimeField() date_end = models.DateTimeField() def __unicode__(self): return self.identite </code></pre> <p>I created this function inside the model:</p> <pre><code>def create_match(self,name): return self.create('name') </code></pre> <p>Then, I try to create a form in the html of my administration page:</p> <pre><code> &lt;form method="post" action="."&gt; {% csrf_token %} &lt;p&gt;&lt;label for="Team A"&gt;Team A:&lt;/label&gt; &lt;input id="Team A" type="text" class="required" name="Team A" maxlength="30"&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="Team B"&gt;Team B:&lt;/label&gt; &lt;input id="Team B" type="text" class="required" name="Team B" maxlength="30"&gt;&lt;/p&gt; (...) &lt;input type="submit" value="" /&gt; &lt;/form&gt; </code></pre> <p>So my questions are:</p> <p>How can I call my function "create_match" so that when I click the submit button it creates a match in my DB with the data I filled in? How can I add this match to a list so that I can display this list to an other page? Finally, how can I delete the match from this list without deleting it from the DB?</p> <p>Thank you very much for your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload