Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

django class-based views with inline model-form or formset -


i have following models:

class bill(models.model):     date = models.datetimefield(_("date of bill"),null=true,blank=true)  class item(models.model):     name = models.charfield(_("name"),max_length=100)     price = models.floatfield(_("price"))     quantity = models.integerfield(_("quantity"))     bill = models.foreignkey("bill",verbose_name=_("bill"),                              related_name="billitem") 

i know possible:

from django.forms.models import inlineformset_factory inlineformset_factory(bill, item) 

and process via standard view.

now wondering, if there way achieve same (meaning: using inline adding/editing items belonging bill) using class based views (not admin-interface).

key points is:

  1. generated formsets within forms.py using inlineformset_factory:

    bookimageformset = inlineformset_factory(bookform, bookimage, extra=2) bookpageformset = inlineformset_factory(bookform, bookpage, extra=5) 
  2. returned formsets within createview class in views.py:

    def get_context_data(self, **kwargs):     context = super(bookcreateview, self).get_context_data(**kwargs)     if self.request.post:         context['bookimage_form'] = bookimageformset(self.request.post)         context['bookpage_form'] = bookpageformset(self.request.post)     else:         context['bookimage_form'] = bookimageformset()         context['bookpage_form'] = bookpageformset()     return context 
  3. used form_valid save form , formset:

     def form_valid(self, form):      context = self.get_context_data()      bookimage_form = context['bookimage_formset']      bookpage_form = context['bookpage_formset']      if bookimage_form.is_valid() , bookpage_form.is_valid():          self.object = form.save()          bookimage_form.instance = self.object          bookimage_form.save()          bookpage_form.instance = self.object          bookpage_form.save()          return httpresponseredirect('thanks/')      else:          return self.render_to_response(self.get_context_data(form=form)) 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -