Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7064557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:50:56+00:00 2026-05-28T04:50:56+00:00

here is my model : I would like to initialise it with a script

  • 0

here is my model :
I would like to initialise it with a script
A page contain a template

class Template(models.Model):
    Nom = models.CharField(max_length=200, blank=True)
    contenu = models. TextField(max_length=80000, blank=True)
    Note_divers = models.ManyToManyField('note.Note_divers', related_name='Template_Note_divers_notes_Note_divers', blank=True)

    def ___str__(self):
        return self.Nom

    def __unicode__(self):
        return self.Nom


class Page(models.Model):
    Template = models.ManyToManyField(Template, null=True, blank=True)
    self_url = models.ManyToManyField('lien.Lien', related_name='pages_lien_self', null=True, blank=True)
    Categorie = models.ManyToManyField(Categorie_Page, null=True, blank=True)
    Liens = models.ManyToManyField('lien.Lien', related_name="Liens sur la page", null=True, blank=True)
    Nom = models.CharField(max_length=200)

and my initialisation script :
The main goal is to create certain pages

    import os

    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

    from django.db.models.loading import cache as model_cache

    if not model_cache.loaded:
        model_cache.get_models()

    from pages.models import Page, Template
    import settings

    t1 = Template(Nom="template_index",contenu="""bienvenue<br><a href="../logout/">logout</a>""")
    t1.save()
    p = Page(Nom="index",Template=t1)
    p.save()

    t2 = Template(Nom="template_indexvide", contenu="""
            <form method="post" action=".">{% csrf_token %}
            <input type="text" name="username">
            <input type="password" name="password">
            <input type="submit" value="login" />
            </form>"""
        )
    t2.save()
    p = Page(Nom="indexvide",Template=t2)
    p.save()

And it gave to me :

   TypeError: 'Template' is an invalid keyword argument for this function

Regards
Bussiere

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:50:57+00:00Added an answer on May 28, 2026 at 4:50 am

    You can’t declare a ManyToMany on instantiation. You need to define and save the instance first, then add the relationships.

    p = Page(nom="indexvide")
    p.save()
    p.templates.add(t2)
    

    (Note also naming conventions: lower case for fields, plural for many-to-many.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code: class Publisher(models.Model): name = models.CharField( max_length = 200, unique = True,
Here is a Django model I'm using. class Person(models.Model): surname = models.CharField(max_length=255, null=True, blank=True)
here is my model class gameUserTrophyInfo(models.Model): user = models.ForeignKey(userInfo) trophy = models.ForeignKey(gameTrophyInfo) date =
Here's a snippet from my application: class PortolioItem(models.Model): ... user = models.ForeignKey(User) contract =
Here's part of my Django app's models.py : class Person(models.Model): birth_year = WideYear(null=True, blank=True)
Here are the domain model classes: public abstract class BaseClass { ... } public
Here's a Django model class I wrote. This class gets a keyerror when I
I have a class called Deal. Deal has vote_scores. I would like to see
I would like to know how can I force a model loading in development
I would like to understand better how Gridview works, in particular auto_fit . Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.