These are chat archives for django/django

8th
Dec 2017
Paul A. Aranguren
@Paulguren
Dec 08 2017 02:26
@fccampelo hey Felipe have you added the application to installed applications in SETTINGS.PY
Anyone here have any experience with AJAX?
Brandon Max
@bmax
Dec 08 2017 02:59
Hi I need help with form fields
I'm trying to change this quantity interfield to be hidden but it's in a catridge mezzanine package and idk how to edit it. https://github.com/stephenmcd/cartridge/blob/master/cartridge/shop/forms.py
:]
@elcolie
Dec 08 2017 07:34
@chris10an
cover_image = models.ImageField(upload_to='buildings/', blank=True, null=True)
Cut out the hero image
@fccampelo It is very obvious. You put app_name in the urlpatterns which is not a valid argument
:]
@elcolie
Dec 08 2017 07:42
The valid argument is name or namespace. Pay attention when you use name is argument of path. namespace is argument of include
djangoReactGuy
@SanskarSans
Dec 08 2017 08:00
why does this not create a readonly field ?
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()
Gauti
@gautamkumar94
Dec 08 2017 08:04
Model form has the functionality of all create reads update and delete
Self.fields['quantity'].widget.attrs['readonly']= True
Try this
djangoReactGuy
@SanskarSans
Dec 08 2017 08:42
nup
that did not work either
djangoReactGuy
@SanskarSans
Dec 08 2017 09:24
@elcolie I tried this
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
did not work
:]
@elcolie
Dec 08 2017 09:29
May I see you Model please and let me know what field you want to be read_only
@SanskarSans
djangoReactGuy
@SanskarSans
Dec 08 2017 09:31
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)
This is my model
:]
@elcolie
Dec 08 2017 10:22
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',
        ]
@SanskarSans
Screen Shot 2560-12-08 at 17.23.44.png
That field will be gray out. The line is thinner than the others.
I use Django2, but it should be OK from 1.9 or above
Luke-VideoLibre
@LukeVideo
Dec 08 2017 10:44

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: )
7319c59a0fd48bec85fd48480ee3a1f02e387c8150e0889eb7a251534bbf7585

a5edca3a5b8fb54ae61d236a5274626ba6a38781573e02202000158faa707191

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
Luke-VideoLibre
@LukeVideo
Dec 08 2017 11:15

OK GOT IT !!!! My bad...
I had to modify the document path

document_path_str = document_path(request.FILES, request.FILES['doc'] )

to

document_path_str = str(fileProof.doc)

Of course. The submited file's name and the actual saved file with it's new name...

print(fileProof.doc)

returns

documents/testFile_Kc2EQx1.txt

But i was calling

document_path(request.FILES, request.FILES['doc'] )

wich returns

documents/testFile.txt

But this file name doesn't always exist...

djangoReactGuy
@SanskarSans
Dec 08 2017 11:19
I am using 1.11 and yes its working now
@elcolie I was only trying to override the widget but your solution worked for me thanks a lot
:]
@elcolie
Dec 08 2017 11:24
@SanskarSans I remember your attempt was my solution when it was Django 1.10. I remember that because last year I did it.
How long you have been working with ReactJS? I want to find someone review my code
djangoReactGuy
@SanskarSans
Dec 08 2017 11:32
Right now I am more active in reactjs than django
i started django earlier but never get a chance to work in it deeply so I am working on one project to get more deeply into it
djangoReactGuy
@SanskarSans
Dec 08 2017 12:07
I am happy to help @elcolie whatever I can
Luke-VideoLibre
@LukeVideo
Dec 08 2017 12:27
No react channel on Gitter ? No react-django channel ? I plan on building a react interface for my project if you want i would be happy to join !
djangoReactGuy
@SanskarSans
Dec 08 2017 12:39
what kind of project it is?
Luke-VideoLibre
@LukeVideo
Dec 08 2017 12:48
Django app to handle a smartcontract call on ethereum. But i also have to build a rest API to handle events and call from other apps. So as i'am gonna have to serialize every view (more or less) i want to write a react version of the site to make it single paged !
I was thinking of a gitter channel for react-django stuff not force anybody to work on my project XD
djangoReactGuy
@SanskarSans
Dec 08 2017 12:57
seems like a cool idea
Luke-VideoLibre
@LukeVideo
Dec 08 2017 13:00
Yeah but also scary ! I am learning to use django at the same time as building the whole thing so... there is a lot to handle. So one step at a time.
:]
@elcolie
Dec 08 2017 13:08
@SanskarSans Do you join reactjs and reactjs/redux?
Anish Shrestha
@annshress
Dec 08 2017 13:17
/87864130+-
Luke-VideoLibre
@LukeVideo
Dec 08 2017 13:19
@elcolie i was looking for react... Didn't give anything... Done!
djangoReactGuy
@SanskarSans
Dec 08 2017 13:44
I am in both group
but nowdays instead of using redux, graphql has made a lot easier in development but for using graphql, i think django graphine library should be used
Luke-VideoLibre
@LukeVideo
Dec 08 2017 13:56
Interresting. So you don't use redux and the whole reducers action calls?
djangoReactGuy
@SanskarSans
Dec 08 2017 14:02
when using graphql, there is no need of redux
but when I am using rest API, i will prefer to use saga with redux
Luke-VideoLibre
@LukeVideo
Dec 08 2017 14:08
OK. So i will have to consider that before chosing graphGl or RestApi....
Any usefull links ? @SanskarSans
djangoReactGuy
@SanskarSans
Dec 08 2017 14:10
links regarding graphql?
Luke-VideoLibre
@LukeVideo
Dec 08 2017 14:12
Yeah. I'm not familiar with the way it works. And if you seen or read something that could save me some time before i start my research on the subject.
djangoReactGuy
@SanskarSans
Dec 08 2017 14:13
in a nutshell, multiple endpoints is needed for restapi. I mean for detail view you have to do api/posts, for single view api/post/1, edit api/post/1/edit etc but when using graphql you only have to call one endpoint and from that endpoint you can do whatever you want to.
sure
this is for the tutorial
Luke-VideoLibre
@LukeVideo
Dec 08 2017 14:13
Thanks !
djangoReactGuy
@SanskarSans
Dec 08 2017 14:14
everything depends on the query when you create the graphql backend
emihir0
@emihir0
Dec 08 2017 17:43
If I use SQLite in dev and postgresql in production; how do I make queries including things like 'unaccent': https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/lookups/#unaccent
I mean, I get how does it work on production, the problem is that I cannot run them on local (obviously because sqlite doesnt implement it); but is there a way for the sqlite to ignore such params?
e.g. replace first_name__unaccent__icontains with first_name__icontains if it's ran by sqlite (as it doesnt support the unaccent)