django Custom ManyToMany save on model Formset Options -


I have a format that is setup to use an included table in the table containing the cookie table and one component The table is found and looks like this

  class RecipeIngredient (models.Model): "Intermediate model between component and recipe. Recipe for many people '' 'volume = model.tegerfilled () measure = model.carfield (max_length = 200) component = model. Foreign (material) preparation = model. Chargefield (max_land = 100, empty = true, zero = true) recipe = model.  

I have created such formats

  IngFormSet = inlineformset_factory (recipe, recipe pointer, formset = BaseIngFormSet, additional = 5)  

The BaseIngFormat was created to turn on the component field (many many in the ingredient table) for the component drop down menu, in the input box, so that I can later input jquery-autocomplete Can I use the box This will save some time from those users who have to scroll a very long list of materials to select from.

class BaseIngFormSet: def add_fields (self, form, index): Super (BaseIngFormat, itself) .add_fields (form, index) form.fields ["component"] = form extreme The boundary ()

The part I am currently trapped in is that when the form is submitted, because the ingredient is no longer in the example table of the component table

I think what needs to be typed in the input box is

I ", then Search about it against any component model such as Ingredient.objects.get (title = "blah")

, then set an object to RecipeIngredient.ingientient in formset, before the formset is valid. Sadly, although I do not know how to do this or how to do it. I go to the shell and then make a DER (formatset) to see if this will highlight any of my issues, but I Did not come with cheese. Suggesting how to take the form of the input in the input of the component, and convert that object into a component? I know that at some point a user can type in a component which is not in the database, and I have a plan to do a lookup for anything that has passed, and if I can not find it in the database, then I will make it And then the object on that new format what I currently have for this form

  import from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404, get redirect from django.template import django.contrib Import .auth.decorators Import_required import from request. Model Imports ModemetSet_Fattery, Import InlineFormset_Exeter from Model, Importer from Processed Incentive Models Import Import Component From Import Form Refresh Form, BaseIngFormat @ login_require DEF recipe (request): IngFormSet = inlineformset_factory (recipe, cookie initiator, formset = base fingerformset, additional = 5) if request.method == 'POST': Form = RecipeForm (request.POST, request.FILES) formset = IngFormSet (request.POST) if form.is_valid () and formset: new_recipe = form.save () instances = examples for instances.sfs (commit = false ): Instance.recipe_id = new_recipe.id example .seave () redirect redirect (new_recipe.get_abso Lute_url ()) Other: form = RecipeForm () formset = IngFormSet (queryset = RecipeIngredient.objects.none ()) return render_to_response ('recipe / recipe_form.html', {'form': form, 'formset': formset,} , Context_instance = RequestContext (request))  

Thanks for any help you can provide

Have you considered using a widget that does not require recognition hacking later on. Maybe something like that? If that's not quite right then take a look at the fields.py file and their custom form fields.


Comments