Answer the question
In order to leave comments, you need to log in
Is it possible to replace a model form field in Django?
there is a form, the 'sizes' field is present in the model as ManyToManyField
class AddForm(forms.ModelForm):
quantity = forms.IntegerField(min_value=1, initial=1)
class Meta:
model = Product
fields = (
'sizes',
'quantity',
def __init__(self, *args, **kwargs):
product_id = kwargs.pop('product_id', None)
super(AddForm, self).__init__(*args, **kwargs)
product = get_object_or_404(Product, id=product_id)
self.fields['sizes'] = forms.ModelChoiceField(queryset=product.sizes.all())
self.fields['sizes'] = forms.BooleanField(initial=False, widget=forms.HiddenInput)
Answer the question
In order to leave comments, you need to log in
you need to send the right header:
https://stackoverflow.com/questions/8485886/force-...
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$file_name.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file_url)); //Absolute URL
ob_clean();
flush();
readfile($file_url); //Absolute URL
exit();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question