These are chat archives for django/django
cover_image = models.ImageField(upload_to='buildings/', blank=True, null=True)
urlpatternswhich is not a valid argument
namespace. Pay attention when you use
nameis argument of
namespaceis argument of
class StockForm(forms.ModelForm): miti = forms.DateField(input_formats=settings.DATE_INPUT_FORMATS) class Meta: model = OpeningStock exclude = ('office', 'timestamp', 'updated', ) def __init__(self, *args, **kwargs): super(StockForm, self).__init__(*args, **kwargs) if kwargs.get('instance') is not None: self.fields['quantity'] = ReadOnlyField()
class StockForm(forms.ModelForm): miti = forms.DateField(input_formats=settings.DATE_INPUT_FORMATS) class Meta: model = OpeningStock exclude = ('office', 'timestamp', 'updated', ) def __init__(self, *args, **kwargs): super(StockForm, self).__init__(*args, **kwargs) if kwargs.get('instance') is not None: self.fields['quantity'].widget.attrs['readonly']= True
Modelplease and let me know what field you want to be
This is my model
class OpeningStock(models.Model): office = models.ForeignKey(OfficeSetup, blank=True, null=True, on_delete=models.CASCADE) miti = models.DateField(null=True) item_group = models.ForeignKey(ItemGroup, blank=True, null=True) item = models.ForeignKey(Item, blank=True, null=True) quantity = models.PositiveIntegerField(default=0) value = models.DecimalField(default=0.0, max_digits=100, decimal_places=2) specification = models.CharField(blank=True, null=True, max_length=600)
from django import forms from openingstocks.models import OpeningStock class OpeningStockForm(forms.ModelForm): quantity = forms.IntegerField(disabled=True) class Meta: model = OpeningStock fields = [ 'miti', 'item_group', 'item', 'quantity', 'value', 'specification', ]
let's do that again.
i have two files in two directories as so
. ├── dir1 │ └── testFile.txt └── dir2 └── testFile.txt
with different sha hashes because content is defferent ( blablabla and bliblibli if you want to try :smile: )
I a user uploads the first file my views will call a getsha function and generate the correct sha as the file has just been saved as testFile.txt and the call the name of the file from the form ( THAT is where i'm wrong AND what i need to change.
Then if a user upload the secon file i get the same hash... BECAUSE the file is saved as testFile_TKAxlil.txt so i call the function with testFile.txt as argument but that is the name of the previously uploaded file.
I need help to find a way to call testFile_TKAxlil.txt
or if the file is uploaded as "file with spaces haha.txt" i need to get the "file_with_spaces_haha.txt" as django renames it for obvious reasons.
def storeproof(request): if request.method == "POST": document_proof_form = documentProofForm(request.POST, request.FILES) if document_proof_form.is_valid(): fileProof = document_proof_form.save() document = request.FILES['doc'] document_path_str = document_path(request.FILES, request.FILES['doc'] ) document_hash = getSha(settings.MEDIA_ROOT + "/" + document_path_str)
def getSha(document): BLOCKSIZE = 65536 hasher = hashlib.sha256() with open(document, 'rb') as afile: buf = afile.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) buf = afile.read(BLOCKSIZE) doc_hash = hasher.hexdigest() print(doc_hash) return doc_hash
Hope someone can help. In fact what i want is the name of the file as displayed in the admin panel.
Doc: Currently: documents/testFile_TKAxlil.txt
OK GOT IT !!!! My bad...
I had to modify the document path
document_path_str = document_path(request.FILES, request.FILES['doc'] )
document_path_str = str(fileProof.doc)
Of course. The submited file's name and the actual saved file with it's new name...
But i was calling
document_path(request.FILES, request.FILES['doc'] )
But this file name doesn't always exist...
ReactJS? I want to find someone review my code
first_name__icontainsif it's ran by sqlite (as it doesnt support the unaccent)