These are chat archives for django/django

12th
Jul 2018
MilanRgm
@MilanRgm
Jul 12 2018 01:28
when creating/registering the user, if i need to create the role for that user, that should be then done in rest-auth registration serializer's save method, right?
Miracle Ayodele
@iammiracle
Jul 12 2018 05:42
Hi guys, how do you save some information to your model via Ajax.
I have tried an option and all I keep getting is, user_id cannot be null, user_id is a foreign key
I changed user_id to char, it worked fine but as foreign key, no
What's your opinion. Thanks
Curtis Maloney
@funkybob
Jul 12 2018 05:46
AJAX is just HTTP started by Javascript
so really, to Django, it makes no difference
though it can imply you're sending data as JSON, not form encoded
Miracle Ayodele
@iammiracle
Jul 12 2018 06:01
Yea i am sending data as JSON
Miracle Ayodele
@iammiracle
Jul 12 2018 06:08
So what do you think
Curtis Maloney
@funkybob
Jul 12 2018 06:35
parse the json, pass it to a ModelForm...
Miracle Ayodele
@iammiracle
Jul 12 2018 11:40
Guys how do you solve posting json data to django model, especially ForeignKey fields
anytime i send to the ForeignKey field, i get Intgerity Error saying ForeignKey field cannot be null, but if i change the field to Char, the record is saved successfully
Curtis Maloney
@funkybob
Jul 12 2018 11:42
that's a bit... vague...
how are you updating the model? what are you setting the value to?
are you creating, or updating the model?
Miracle Ayodele
@iammiracle
Jul 12 2018 11:46
data = {'amount_paid': 2000, 'reference_id': 'hdjdii34', 'user_id': 2}
r = requests.post("http://127.0.0.1:8000/payment/api/payment/", data=json.dumps(data), headers=headers)
and i get this error in return IntegrityError: (1048, "Column 'user_id_id' cannot be null")
hope you understand me @funkybob
Curtis Maloney
@funkybob
Jul 12 2018 11:48
you've not shown me any details about what I asked... what are you doing django side ?
Miracle Ayodele
@iammiracle
Jul 12 2018 11:51
on django side, i am trying to make perform an operation, whereby when the user clicks on a button, an inline form to make payment comes up and after the payment is successful, i need to save few informations from the payment response to my model
javascript was used for the inline payment, so inside the javascript, if the payment is successful, some informations should be sent to the api endpoint provided
i hope you now get me
Miracle Ayodele
@iammiracle
Jul 12 2018 11:58
@funkybob
Curtis Maloney
@funkybob
Jul 12 2018 12:10
again, you're not showing me any of the django code...
Nathan Kirui
@Nkirui
Jul 12 2018 12:33
hey guys i have this function
def driverremove(request, pk):
driver= get_object_or_404(DriverProfile, pk=pk)
if request.method == 'POST':
driver.delete()
return redirect('driverlist')
return render(request, 'employer/driverconfirmdelete.html',{'driver':driver})
i want to update the object index after deletion..
anyone has the idea?
image.png
Curtis Maloney
@funkybob
Jul 12 2018 12:36
what do you mean by "object index"?
Nathan Kirui
@Nkirui
Jul 12 2018 12:37
pk
Curtis Maloney
@funkybob
Jul 12 2018 12:37
it would be very bad to change the pk of records
why do you care what the value is?
Nathan Kirui
@Nkirui
Jul 12 2018 12:38
not really changing but updating the sequence after i have deleted ,have you managed to check on my screen shot?
Curtis Maloney
@funkybob
Jul 12 2018 12:39
I looked
do you mean you want to reset the sequence object from which the PK values are generated, so it's set at the highest value?
Nathan Kirui
@Nkirui
Jul 12 2018 12:40
yes ...
Curtis Maloney
@funkybob
Jul 12 2018 12:41
why?
what problem are you trying to solve using this ?
Nathan Kirui
@Nkirui
Jul 12 2018 12:42
i want the the table to look neat and updated..with the remaining items.
Curtis Maloney
@funkybob
Jul 12 2018 12:43
resetting the sequence won't renumber records
stop treating the PK like it's a meaningful value, besides an unique record ID
again, what actual real problem do you want to try to solve?
Nathan Kirui
@Nkirui
Jul 12 2018 12:49
for example above ,i have deleted item, 1,2,3,5,6, so my table suppose to read these remaining items as 1,2 as opposed to 4 and 7..
Curtis Maloney
@funkybob
Jul 12 2018 12:51
once again... why do you care at all?
they're not even numbers a user should ever see
anyway... time for me to sleep
Nathan Kirui
@Nkirui
Jul 12 2018 12:56
thanks for your input, sleep well .let me dig out and find a solution.
Nischith
@Nischith4
Jul 12 2018 13:02
Guys, can we use python for iOT?
Chuma Umenze
@chumaumenze
Jul 12 2018 15:04
data = {'amount_paid': 2000, 'reference_id': 'hdjdii34', 'user_id': 2}
r = requests.post("http://127.0.0.1:8000/payment/api/payment/", data=json.dumps(data), headers=headers)
Consider :
r = requests.post("http://127.0.0.1:8000/payment/api/payment/", json=data, headers=headers)
MilanRgm
@MilanRgm
Jul 12 2018 17:12
class LoginAPI(views.APIView):

    serializer_class = LoginSerializer

    def post(self, request, *args, **kwargs):
        reply = {}
        serializer = self.serializer_class(data=request.data)
        if serializer.is_valid(raise_exception=True):
            user = serializer.save()
            if user:
                token = Token.objects.create(user=user)
                print('token', token)
                reply['data'] = serializer.data
                reply['token'] = token.key
                print('reply', reply)
                return Response(reply, status.HTTP_200_OK)
        reply['errors'] = serializer.errors
        return Response(reply, status.HTTP_400_BAD_REQUEST)
Why am i getting 'User' object has no attribute 'items' error when login?
this is my serializer
class LoginSerializer(serializers.ModelSerializer):
    username = serializers.CharField(max_length=32)
    password = serializers.CharField(
        min_length=8,
        max_length=50,
        write_only=True
    )

    class Meta:
        model = User
        fields = ('id', 'username', 'password', )

    def validate(self, data):
        user = authenticate(**data)
        if user and user.is_active:
            return user
        raise serializers.ValidationError('Unable to login')
it works till validate method
Esther Suh
@estherjsuh
Jul 12 2018 22:24
Hi! has anyone deployed their Django app with Docker?
fsecada01
@fsecada01
Jul 12 2018 23:42
Hey guys!! Anyone here using Semantic UI for their Django frontend? I have a question about modals.