I'm trying to figure out how get_initial will work in this instance. I know I will have to pass the asset_tag.pk through the url to the FixedAssetCopyView but not sure what to set for my initial data. Assuming I just want to set the "manufacturer" = to the manufacturer of the fixed_asset.pk that gets passed through the url, what would I put in my view? Also does my url look right? Thanks
This is my View class FixedAssetCopyView(LoginRequiredMixin, CreateView): fields = ("asset_tag=''", "serial_number=''", "manufacturer", "model_number", "description", "purchase_date", "purchase_price", "purchased_from", "purchase_condition", "asset_type", "owner", "location", "active", "inactive_date", "comments") model = FixedAsset template_name = 'administration/fixed_assets/fixed_asset_form.html' def get_initial(self): initial = super().get_initial() initial["manufacturer"] = fixed_asset.pk.manufacturer return initial And this is my url url(r'^fixed_assets/copy/(?P<pk>\d+)/$', fixed_assets.FixedAssetCopyView.as_view(), name='fixed_asset_copy'), On Wednesday, February 28, 2018 at 10:42:48 AM UTC-7, Alexander Joseph wrote: > > I'd like to create a CBV to allow users to copy a record, except for item > specific information. - I'm making a fixed assets app and if there are 2 of > the same laptop I'd like the user to be able to make one record in the > database, then copy it minus the serial number and asset tag number which > would be the only info the user would have to fill in to copy that laptop. > > Is there a way to do this by modifying the CreateView somehow? Thanks > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7d1de04e-9cc7-4296-bbe4-0e809b12b044%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.