Re: How to commit ManyToManyField with ModelForm
I tried to recreate tables, and it's done. But it makes no change to my plobrem. Please help me out (;_;) On 7月9日, 午後7:59, Sævar Öfjörð <saeva...@gmail.com> wrote: > Have you tried resetting your database and syncing it again? > If there are columns missing it sounds like you added them after you > did a manage.py syncdb > Django will not alter your tables after they have been created. More > info on this > here:http://docs.djangoproject.com/en/dev/ref/django-admin/?from=olddocs#s... > > So I would try: > > python manage.py reset appname > python manage.py syncdb > > Just keep in mind that you'll lose your previously stored data. > > -Sævar > > On Jul 9, 8:10 am, yugori <yuya.gor...@gmail.com> wrote: > > > Hi, I'm beginner of Django > > Now I try to make Product Management Tool with Django. > > So I wrote some code. > > > models.py > > //--- > > from django import forms > > from django.db import models > > > # ex('ie8','InternetExplorer8') > > class Browser(models.Model): > > id=model.CharField('id',primary_key=True) > > name=model.CharField('name') > > > def __unicode__(self): > > return self.name > > > # ex('iphone3','iPhoneOS3') > > class Device(models.Model): > > id=model.CharField('id',primary_key=True) > > name=model.CharField('name') > > > def __unicode__(self): > > return self.name > > > # ex('site01','MySite','browser[]','device[]') > > class Product(models.Model): > > id = models.CharField('id', primary_key=True) > > name = models.CharField('name') > > support_browser = models.ManyToManyField(Browser) > > support_device = models.ManyToManyField(Device) > > > def __unicode__(self): > > return self.name > > > class ProductForm(forms.ModelForm): > > class Meta: > > model = Product > > ---// > > > > > view.py > > //--- > > def create(request): > > if request.method == 'POST': > > form = ProductForm(request.POST) > > if form.is_valid(): > > form.save() > > return HttpResponseRedirect('/product/detail/'+form.id > > +'/') > > else: > > print form.errors > > errors = form.errors > > return render_to_response('Product/create.html',{'errors': > > errors,'form':form}) > > > else: > > form = ProductForm() > > > return render_to_response('Product/create.html',{'form':form}) > > ---// > > > > > create.html > > //--- > > > > create > > > > > > {{ form.errors }} > > > > ID{{form.id}} > > > > > > NAME{{form.name}} > > > > > > Support Browser > > {{form.support_browser}} > > > > > > Support Device > > {{form.support_device}} > > > > > > > > > > > > > ---// > > > > > 1.Access to /product/create/ - it works good! > > 2.Complete form and submit - it works good! > > 3.Watch table 'product' - it works good? There's no column > > 'support_browser' and 'support_device'. > > 4.Watch intermidieval table 'product_browser'(autogenerated) - it has > > no rows... > > > What's wrong? > > Please tell me.. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to commit ManyToManyField with ModelForm
Hi, I'm beginner of Django Now I try to make Product Management Tool with Django. So I wrote some code. models.py //--- from django import forms from django.db import models # ex('ie8','InternetExplorer8') class Browser(models.Model): id=model.CharField('id',primary_key=True) name=model.CharField('name') def __unicode__(self): return self.name # ex('iphone3','iPhoneOS3') class Device(models.Model): id=model.CharField('id',primary_key=True) name=model.CharField('name') def __unicode__(self): return self.name # ex('site01','MySite','browser[]','device[]') class Product(models.Model): id = models.CharField('id', primary_key=True) name = models.CharField('name') support_browser = models.ManyToManyField(Browser) support_device = models.ManyToManyField(Device) def __unicode__(self): return self.name class ProductForm(forms.ModelForm): class Meta: model = Product ---// view.py //--- def create(request): if request.method == 'POST': form = ProductForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/product/detail/'+form.id +'/') else: print form.errors errors = form.errors return render_to_response('Product/create.html',{'errors': errors,'form':form}) else: form = ProductForm() return render_to_response('Product/create.html',{'form':form}) ---// create.html //--- create {{ form.errors }} ID{{form.id}} NAME{{form.name}} Support Browser {{form.support_browser}} Support Device {{form.support_device}} ---// 1.Access to /product/create/ - it works good! 2.Complete form and submit - it works good! 3.Watch table 'product' - it works good? There's no column 'support_browser' and 'support_device'. 4.Watch intermidieval table 'product_browser'(autogenerated) - it has no rows... What's wrong? Please tell me.. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: models.py import from other models.py
This problem is resolved. What I did is 1.comment out "models.ManyToManyField" line and execute "manage.py syncDB". 2.Back to code "models.ManyToManyField" line and execute "manage.py evolve --hint --execute" Then appli_master table was auto-generated. I don't know why this way goes right. But, now I have another problem. I use ModelForm to deal the table, I try to submit and form.save() then the data column is added Appli table successfully, but appli_master table has no updated data. orz.. On Jul 9, 2:15 am, Nuno Maltez <nuno.li...@gmail.com> wrote: > What error do you get when you execute 'manage.py syncDB'? Could you > paste it here? > > Nuno > > On Thu, Jul 8, 2010 at 2:28 AM, yugori <yuya.gor...@gmail.com> wrote: > > Hi, I'm beginner. > > > I tried to execute 'manage.py syncDB' command, > > but it's not work. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
models.py import from other models.py
Hi, I'm beginner. I tried to execute 'manage.py syncDB' command, but it's not work. My package is like .. MyProjectMaster---models.py | Appli-models.py MyProject/Appli/models.py is .. //- from Master.models import WebBrowser class Appli(models.Model): # id id = models.CharField(u'id', max_length=20, blank=False, primary_key=True) # support_browser support_browser = models.ManyToManyField(WebBrowser,blank=True) def __unicode__(self): return self.name // I tried that with comment out import from above code,it's work. Is this bad design? I wish to anyone help me. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.