简体   繁体   中英

Django; Can't Access to Other Models inlineformset_factory Fields

I have a successfully working inlineformset_factory form. I create this model with a button and inherit the data in it from another model. However, I was not able to access the inlineformset_factory fields in the other model.

def create_offer_button(request):
    if request.method == "POST":
        post = request.POST.get("post_pk")
        obj = RequestModel.objects.get(pk=post)
        if obj.is_accepted:
            OfferModel.objects.create(request_model_name=obj,
                                      request_title=obj.request_title,
                                      delivery_time=obj.delivery_time,
                                      shipping_country=obj.shipping_country,
                                      shipping_address=obj.shipping_address,
                                      preferred_currency=obj.preferred_currency,
                                      shipping_term=obj.shipping_term,
                                      delivery_term=obj.delivery_term)

            obj.is_offer_created = True
            obj.save()
        return redirect(request.META.get("HTTP_REFERER"))

How can i access to RequestModel's inlineformset_factory fields?

I tried many methods but I could not reach the formset fields of the inheritance model.

I solved it:

obj_items = RequestItem.objects.filter(request_model=obj)
for item in obj_items:
    OfferRequestItem.objects.create(offer_model_id=obj.id, product_name=item.product_name)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM