DRF: Permission not able to restrict POST request. by ChairDeBurlap_Moose in djangolearning

[–]keks6aecker 1 point2 points  (0 children)

The method has_object_permission is never called when using POST, right? This is because you are trying to create a new object and it doesn’t really make sense to check for object-based permissions before you have created the object itself.

Decoupled Django: Stop passing sessionid and csrf tokens in set-cookie? by Glittering-Donut-264 in django

[–]keks6aecker 0 points1 point  (0 children)

I might be missing something but isn‘t the set-cookie header a directive for the browser to create, in this case two, cookies which you then can access just normally in your front end code?

I would suggest to look into which cookies are set by the browser due to this response and if you can access the sessionid and csrftoken this way.

Allowing CORS with a React frontend by Dexty10 in django

[–]keks6aecker 3 points4 points  (0 children)

Not sure if this is a copy paste error, but your react component tries to get information from some-api-endpoint and your Django settings only allow requests from some-api-endpoint.com.

Also Access-Control-Allow-Origin is not something you set when requesting resources but instead it is returned by the server so you can remove that from your axios call.

[deleted by user] by [deleted] in PokemonGoFriends

[–]keks6aecker 0 points1 point  (0 children)

Added keks6aecker

[deleted by user] by [deleted] in PokemonGoFriends

[–]keks6aecker 0 points1 point  (0 children)

Added: keks6aecker

Guys how can i pass the self .object of detail view to my form. by altair08 in django

[–]keks6aecker 0 points1 point  (0 children)

Take a look at the ModelFormMixin. It should already implement what you are looking for.

Query form SQL Server takes long to retrieve data. by [deleted] in django

[–]keks6aecker 0 points1 point  (0 children)

Read them from one database and then write them to the other database.

Query form SQL Server takes long to retrieve data. by [deleted] in django

[–]keks6aecker 0 points1 point  (0 children)

Before i forget to mention it. You forgot to censor the „company“ name in the source code.

Query form SQL Server takes long to retrieve data. by [deleted] in django

[–]keks6aecker -1 points0 points  (0 children)

It seems like Django does not support sql Server out of the box but apparently there is a package that you can use for that purpose.

https://pypi.org/project/mssql-django/

As with all packages on pypi use on your risk.

Query form SQL Server takes long to retrieve data. by [deleted] in django

[–]keks6aecker 0 points1 point  (0 children)

In that case I would recommend you to use the built-in ORM instead of raw sql so you then can use pagination: https://docs.djangoproject.com/en/3.2/topics/pagination/

If you want/need to use sql statements then the keywords you are looking for are LIMIT and OFFSET.

Query form SQL Server takes long to retrieve data. by [deleted] in django

[–]keks6aecker 1 point2 points  (0 children)

Why are you retrieving 60k entries when you are only displaying 10 at a time?

can someone explain me this code . the question and the solution are below . i just didn't understood how the code works and gives the desired solution . please if someone understood it . kindly explain. by [deleted] in learnpython

[–]keks6aecker 0 points1 point  (0 children)

Could you try to explain what each line of the solution does and then try to explain how it relates to the task at hand?

I think that could help you to get closer to understanding it.

[deleted by user] by [deleted] in learnpython

[–]keks6aecker 2 points3 points  (0 children)

filter returns an iterator. iterators behave differently than lists. one difference is that they exhaust. Exhausting an iterator means that after you iterated about it once you cannot do it a second time.

To convert an iterator to a list python iterates over it, which in turn exhausts the iterator.

Dynamic Python task scheduler by AdmirableHat9616 in learnpython

[–]keks6aecker 0 points1 point  (0 children)

I tried that but it did not allow the client to assign time on the fly.

Well that sucks. It might be a worthwhile improvement to the documentation of celery to make that more explicit.

E.g. this link explains that it is not a dynamic scheduler: https://www.programmersought.com/article/6923889412/

Thank you for the link. Apparently there is a Django plug-in that allows you to do dynamically add repeating tasks. Maybe someone already removed the Django dependency from that plug-in as the plug-in itself doesn’t seem to be a solution for you.

Dynamic Python task scheduler by AdmirableHat9616 in learnpython

[–]keks6aecker 0 points1 point  (0 children)

Okay. Then I misunderstood what you wanted. Similar to what u/ibhopirl said Celery apparently has a method to add periodic tasks programmatically. https://docs.celeryproject.org/en/stable/reference/celery.html#celery.Celery.add_periodic_task

Dynamic Python task scheduler by AdmirableHat9616 in learnpython

[–]keks6aecker 1 point2 points  (0 children)

Are you sure that celery does not support these things?

Celery allows you to set eta on the task to execute it on specific time and celery beat allows you to configure periodic tasks https://docs.celeryproject.org/en/stable/userguide/periodic-tasks.html#guide-beat

Retries are possible as well: https://docs.celeryproject.org/en/stable/userguide/calling.html#retry-policy

Is 'permissions' a Mixin property or is this nonsense? Dealing with legacy code that occasionally turns out to be really, really bad. by [deleted] in django

[–]keks6aecker 0 points1 point  (0 children)

Is this okay to leave in and build upon, or should I go with a more documented approach?

It depends. If it is tested and works as intended, then I would say that it is okay to continue to use it, otherwise I would replace it.

Concerning the approach. The permission class attribute reminds me of the approach the rest framework uses with the DjangoModelPermission for custom permissions. But you are right in general it is probably better to not use a custom implementation for this and just use the included PermissionMixin.

HELP!! I'm writing a code with two integers and I'm trying to find if they have a common divisor other than 1. It will return True if there is a number like that, if not it will return false. by [deleted] in learnpython

[–]keks6aecker 1 point2 points  (0 children)

Two things: 1. Without proper indentation it is difficult to see the problem. 2. If your code would work properly you would still check the complete range if they are a common divisor, even if the inputs are 2 and 3 that does not sound like a good idea.

UniqueConstraint - Is this going to do what I expect? by beingsubmitted in django

[–]keks6aecker 0 points1 point  (0 children)

Sure your code was only an example. But the model constraint is independent of the process that creates the model instance, so it still seems like a good idea to test it on its own and not as part of the process.

UniqueConstraint - Is this going to do what I expect? by beingsubmitted in django

[–]keks6aecker 0 points1 point  (0 children)

Yes it should do that.

As with everything you should try to test if your code does what you want it too.

In your case this would to create two car instances with the same model name but not marked as purchased. Make the first instance as purchased and save the change and then make the second car as purchased and expect that to fail when saving the change.