|
NtotheTC posted:objects.filter expects keyword arguments that it tries to iterate over: filter(blah=self.request.user) where blah is the name of the foreign key field for user on your Case model Man I'm dumb. Fixed, thank you!
|
# ? Jun 9, 2020 15:31 |
|
|
# ? Jun 3, 2024 21:55 |
|
I have what I think is a common problem, but I can't seem to find a solution. I want to show 2 form fields where the first decides whether the 2nd is displayed. e.g. code:
I have many forms like this so I'd like a generic way to solve it. What I'd like to do is programmatically define the relationship between the Field 1 & 2 in the Form definition, and have some general-purpose JS parse that relationship and handle the client-side show/hiding. It feels like this problem is common enough that someone must have solved it, but I can't seem to find any libraries that would assist here. Any ideas?
|
# ? Jun 10, 2020 02:01 |
|
minato posted:I have what I think is a common problem, but I can't seem to find a solution. I’m a Django newbie but this is trivially easy in Dash (Flask) with callbacks.
|
# ? Jun 10, 2020 03:40 |
minato posted:The standard solution is to use Javascript to show/hide Field 2 when "Baz" is selected/de-selected. But this seems fragile, because now I have to write JS code in the template that's tightly-coupled to the Form definition but yet is in a different file. And if someone renames "Baz" or adds a new item to Field 1, it might break that JS code. Without comprehensive tests, it's going to be easy to break this code. Django Forms are great for their simplicity, but I don't think they are really meant for anything more complex than the absolute basics. For that sort of behavior you would definitely need some client side code. Looks like django-dynamic-form-fields would at least abstract it away from you.
|
|
# ? Jun 10, 2020 08:05 |
Yeah, I was hoping to see if someone would pop up with some suggestion of a cool library I'd never heard of, but my reaction to this is that if you want to have dynamic client-side functionality in your form, it's going to necessarily involve javascript. In fact, for your use case (where you're trying to build kind of a generalized platform for other people to use), I kinda think this calls for an SPA like Angular/React/Vue, where you would use Django to feed it with an API via Django REST Framework (whose serializers largely operate like forms and integrate all the same form functionality like validation, etc). You can add mixins that let you create serializers that use common functionality that you add to all of them, so like if you want to make specialized form fields whose behavior depends on other fields, you could define those in the Meta class and then have methods that hook into the __init__ to serve them appropriately via the API. And then you could centralize the configuration of your form objects in yaml files or a specialized object managed via the admin, or something like that, so the python code changes as little as possible, but a front-end person can set up a form just using a standard configuration format. This would take a lot of designing, and this is just shooting from the hip, but it's probably the direction I'd go with it. Data Graham fucked around with this message at 12:02 on Jun 10, 2020 |
|
# ? Jun 10, 2020 12:00 |
|
I'm a huge Django newbie and I'm having a difficulty with a Django project running on Google App Engine. I tried to upgrade from Django 2.2.10 to the latest version, Django 3.0.7. I also incidentally upgraded Django REST Framework from 3.8.2 to 3.11.0. It all seemed to go surprisingly smoothly at first. Now, however, I started to get error logs connected to user authentication. I'm getting exceptions like these: code:
code:
Is there anything I can do that might get me on the right track to fix this? I have been wondering if maybe it has something to do with my settings but I feel like I lack the experience to know what I might need to change in there. edit: This was caused by a namespace conflict and I'm an idiot Falls Down Stairs fucked around with this message at 08:09 on Jun 11, 2020 |
# ? Jun 10, 2020 21:36 |
|
What's the go to Django plugin for payment processing for an American centric ecommerce website these days
|
# ? Jul 10, 2020 02:20 |
|
Hadlock posted:What's the go to Django plugin for payment processing for an American centric ecommerce website these days Any third party payment processor seems to have a Django version I easily found one for square, stripe and PayPal
|
# ? Jul 10, 2020 02:27 |
|
Ok great thanks. That makes sense that they would want it to be easy for developers to integrate their product Lemme ask a similar question, if I wanted to add a payment workflow, is there a payment processor that's easiest to start with? My money is on PayPal
|
# ? Jul 10, 2020 10:01 |
|
Hadlock posted:Ok great thanks. That makes sense that they would want it to be easy for developers to integrate their product depends what you're selling, there are some hoops you have to jump through if it's something age restricted (alchohol/tobacco) or similar but last time I tried it PayPal was the simplest to just get up and running
|
# ? Jul 10, 2020 11:08 |
|
I thought stripe was really easy to integrate, but they also suck to deal with if you have to deal with fraud (everyone sucks this way). I would probably get started with them and when it’s worth it to optimize fees get a merchant account with better terms through another vendor
|
# ? Jul 10, 2020 16:15 |
|
I see tons of django projects with the secret key in the public repo. How much of a security risk is that? Everywhere I read says its a critical one but I dont understand why. What can someone actually do with a secret key? I read its the seed for the hash for the passwords...I take it if someone gets DB access they can then be decrypted or ...un...salted?
|
# ? Sep 12, 2020 16:57 |
|
It's also used as the seed for the built-in CRSF protection that prevents phishing attacks.
|
# ? Sep 12, 2020 20:37 |
But all you gotta do is change it before you go live and not check in the new one to source control. Which, well, lol
|
|
# ? Sep 12, 2020 21:53 |
|
Hadlock posted:Ok great thanks. That makes sense that they would want it to be easy for developers to integrate their product Stripe is the best in my opinion.
|
# ? Sep 21, 2020 18:21 |
|
Anyone have any opinions on tracking migrations under git? I know it’s the recommended practice... but I’ve been burned by it many times where I’ll end up with a bunch of conflicts and/or a hosed up database. I’ve started git ignoring everything past the __init__.py file in my migrations folders and it has been fine so far. I can see this being a problem if I need to do some custom migration stuff (like adding postgres database extensions or whatever) but other than that I’m failing to see the benefit. I will say that I do work with a very small team on very small web apps, so maybe that’s why I’m not seeing the benefit here.
|
# ? Sep 22, 2020 14:05 |
|
punished milkman posted:but I’ve been burned by it many times where I’ll end up with a bunch of conflicts and/or a hosed up database. What usually is the problem when this happens? The only problems I run into is when I do a merge request, someone has already made their own migrations. In that case I just pull their code (solve any conflict if needed) and makemigrations over the new code with my changes. How do you run the migrations when you deploy to production? Always from zero? In that case, won't you lose existing information? Using migrations, you can also revert to a previous state if needed for some reason, that also seems important.
|
# ? Sep 22, 2020 14:29 |
|
punished milkman posted:Anyone have any opinions on tracking migrations under git? Always do it. The problems with merge conflicts you're experiencing are nothing compared to the pain of spending 3 hours debugging something only to find out it's because your teammate didn't check in a migration, and I cannot begin to imagine how you're handling production deployments WITHOUT having migrations checked in as part of it. that sounds like an absolute nightmare. e; if this is only an issue because you haven't got any apps in deployment at the moment and they're all in development so there's a lot of new migrations being added, then make it a regular weekly/biweekly dev task to squash your migrations so that it's more manageable NtotheTC fucked around with this message at 14:35 on Sep 22, 2020 |
# ? Sep 22, 2020 14:33 |
|
I figured I was being a dumbass, thanks for clarifying. I have one big “production” app (it’s an app only available on a local network with like 10 users) where the database models are continually getting expanded and our migrations aren’t being tracked on git. Whenever I need to update things, I just log onto the prod server, pull the changes from our master branch, and makemigrations/migrate. So far so good at least? (this is what happens when a biologist becomes a web developer btw)
|
# ? Sep 22, 2020 15:08 |
Remember that the whole point of migrations is reconstructability. You want to be able to deploy your app to a new environment, or prod, from scratch and run migrate and it will build the database to exactly the state it is in everybody's dev environment. Including data migrations, for infrastructural data and fixtures. You can't really do this without having all the migrations committed to the repo so you can reconstruct history. Similarly you want a new developer to be able to check out the codebase, run migrate, and they'll have a database just like everyone else's/production. Everybody contributing code needs to be committing all their new migration files as soon as they're created, and everyone else needs to be regularly pulling them down and applying them so they're all in sync. This applies even if it's only one developer environment plus production. If your issues stem from multiple people working in parallel and making so many database changes at the same time that they cause merge conflicts, they all need to get in the habit of syncing each other's code changes more regularly and/or discussing/reviewing their DB changes before they go ahead and make them.
|
|
# ? Sep 22, 2020 16:26 |
|
I'm running into issues logging server errors with DRF. JSON POST requests include the data in the request body, which is not logged or reported through any of the standard Django mechanisms. I'm using bugsnag as well as admin emails with a pretty boilerplate Django logging configuration. Is there any easy way to get the request body included along with the POST, GET, etc data that is already reported?
|
# ? Sep 28, 2020 16:57 |
|
Any wagtail folks? I am starting up a site using it, and so I will have lots of stupid newbie questions, and if you are dumb enough to tell me you know it, I'll ask them here!
|
# ? Sep 29, 2020 01:11 |
I've used it a fair amount. oh crap
|
|
# ? Sep 29, 2020 01:11 |
|
I’ve used Django CMS twice now but not for any good reason over wagtail or mezzanine. Any opinions amongst goons as to one being way better? With CMS I basically install and forget.
|
# ? Sep 29, 2020 01:26 |
|
Wagtail is quite a change over a standard Django project (or it used to be). I haven't used it for ages but the guys that run it are really helpful so if there are any communities out there for it I imagine they'll all be really useful.
|
# ? Sep 29, 2020 10:01 |
|
Data Graham posted:I've used it a fair amount. Muahahahaahah.... Question the first: So I have a bunch of Documents (PDFs) in a Collection, and more will be added over time. I have a Page where I want to have links to all the documents in that one collection. I am apparently too blind and / or stupid to see how to do this.
|
# ? Sep 29, 2020 14:03 |
Lumpy posted:Muahahahaahah.... So, I haven't used Collections for anything myself, but from tinkering with them a bit just now it looks like (as with a lot of Wagtail stuff) in order to do anything with it like what you're talking about, you need to basically follow standard Django patterns and treat them like any other model. I don't know how deeply you've gotten into building your custom page models, but you'll have to add the collection (or its contents) you're looking for into the page context so the template can find it. Like this: Python code:
|
|
# ? Sep 29, 2020 14:40 |
|
Data Graham posted:So, I haven't used Collections for anything myself, but from tinkering with them a bit just now it looks like (as with a lot of Wagtail stuff) in order to do anything with it like what you're talking about, you need to basically follow standard Django patterns and treat them like any other model. I don't know how deeply you've gotten into building your custom page models, but you'll have to add the collection (or its contents) you're looking for into the page context so the template can find it. Thanks! Follow up: where did you find that? Their docs are amazing for certain things, but you'd never know there was a wagtail.core.models.Collection by searching them.
|
# ? Sep 29, 2020 16:15 |
Much of what you've got to do in Django land is overriding methods and classes that are provided by the core libraries. So you do have to dig through those libraries to see what's available. A lot of it you can infer just from experience; like, a well-behaved Django package will have a models.py where the models are defined, indeed probably multiple ones in different apps (which you can deduce from the fact that they show up categorized in the admin, like Documents under Wagtail Documents (which is the verbose name of the "documents" app in wagtail)). e: To be clearer — what I did specifically was, I looked at a Document in the admin, and saw that Collection was a property on each one, and referred to what appeared to be a foreign-keyed object. So I figured (also basing it on the fact that you create Collections as individual objects in the CMS admin) that Collection is a model provided by the Wagtail architecture somewhere. So the next thing was I went into the wagtail.documents.models module to see how the Document model was defined; and saw that it inherits from a class called CollectionMember, which is defined in another module (core) as a thing that's fk'ed to Collection, which when referred to elsewhere is imported from the wagtail.core.models package. Images are the same way, from wagtail.images.models. I also saw that CollectionMember has related_name="+", which means it suppresses Collection instances from having a *_set created on them, presumably because there are potentially tons of other models inheriting from CollectionMember and keeping all those namespaces straight would probably be a nightmare of instability and not very useful. So hence you have to query for members of a collection in the other direction. The fact that Collections aren't exposed in the admin or documented as a thing you should be able to access in templates, I think, is an artifact of Collections not really being intended for what you're doing with them; I think it's meant more as a convenience for the CMS itself, so non-technical editors can group things into conceptual buckets to manage data better. Are you using an IDE? PyCharm (for example) will let you drill down into the definitions of the methods and classes that you're overriding, and will give you a good sense of how things are laid out and what's available for you to pull into your code to tinker with. Data Graham fucked around with this message at 17:05 on Sep 29, 2020 |
|
# ? Sep 29, 2020 16:54 |
|
ORM question: I'm reading https://docs.djangoproject.com/en/2.2/topics/db/queries/#querysets-are-lazy and it's making me ask some questions. Say I have code that looks kind of like this:code:
|
# ? Sep 29, 2020 19:56 |
|
That's entirely correct. Querysets are always evaluated/executed at the last possible moment, usually when you try to access the results or slice it. Every time you call a .filter(), .all(), .none() a new Queryset is returned. Since you have 4 querysets created, but only use data from 3, you get 3 SQL queries.
|
# ? Sep 29, 2020 21:28 |
|
CarForumPoster posted:I see tons of django projects with the secret key in the public repo. How much of a security risk is that? Everywhere I read says its a critical one but I dont understand why. What can someone actually do with a secret key? I read its the seed for the hash for the passwords...I take it if someone gets DB access they can then be decrypted or ...un...salted? Similarly, is there any reason not to do this for development instances of the application, if it's acceptable for all cookies to be invalidated whenever the application restarts? Python code:
|
# ? Sep 30, 2020 20:19 |
|
cookiecutter installs a ton of poo poo I don’t need, for a new project so you guys just use startproject and build up? I like the custom settings files and custom wsgi.py to make it work. Basically looking for that lightweight if it’s a thing.
|
# ? Oct 1, 2020 01:25 |
|
Hed posted:cookiecutter installs a ton of poo poo I don’t need, for a new project so you guys just use startproject and build up? My team forked cookie cutter and customized it to fit our needs. You can always do that
|
# ? Oct 1, 2020 02:18 |
I'm not sure why I'm struggling so much with this, I have been googling and troubleshooting like crazy but I'm running up against a wall. With Django Rest Framework, what's the best way to accept optional parameters on a model creation that will then let me do something with the returned instance and those specific parameters? Say I want to track Presents and Wishlists, which is a list of Presents. Presents can be created without being on a Wishlist (sorry kids), but I also want the possibility to, when creating a Present, automatically add it to a Wishlist. Both the Present and Wishlist models have a ManyToManyField through a WishListPresent model which I specifically created (I know you don't need to but.. I can't get this stuff working so I'm trying to be as explicit as possible). The relationship works and I can manually enter items in the shell by creating a Present, saving, creating a Wishlist, saving, then WishlistPresent(present=present, wishlist=wishlist).save(), but I don't know where/how to fit this in to the normal DRF Present creation process. I thought I would be able to just add optional extra parameters to the Present creation call, which in the shell would look like: code:
code:
code:
Sulla Faex fucked around with this message at 20:57 on Nov 30, 2020 |
|
# ? Nov 30, 2020 20:39 |
Sulla Faex posted:Say I want to track Presents and Wishlists, which is a list of Presents. Presents can be created without being on a Wishlist (sorry kids), but I also want the possibility to, when creating a Present, automatically add it to a Wishlist. I would switch up the schema a bit, the list of Presents seems odd to me. Do you need a Present to be part of multiple Wishlists? I was thinking it should be along the lines of: code:
|
|
# ? Nov 30, 2020 21:22 |
fletcher posted:I would switch up the schema a bit, the list of Presents seems odd to me. Do you need a Present to be part of multiple Wishlists? The reason I went in this direction is because I wanted specifically for presents and wishlists to be pretty flexible (with the idea of users sharing and/or extending multiple presents and wishlists), but if it don't work then it ain't flexible. So you're right, I'll simplify and get the concept working and then see later if I actually need some specific solution (which I can tackle when I'm more confident) or if I was just over-engineering from the start and missing the basics. It's a better approach anyway, I meant to practice test-first development and I completely spaced on it.. probably could have caught the "why are you starting with a needlessly complicated idea again?" fallacy Thanks! Sulla Faex fucked around with this message at 10:35 on Dec 2, 2020 |
|
# ? Dec 2, 2020 10:33 |
|
Does anyone have any ideas / examples of how to design a project with different databases for different users? The idea is you would log in with username / password / group code and then be in a different database based on the group code (with no shared auth, each database has its own auth table). Database routers have no access to requests. There's some bullshit online about using thread local variables which seems dumb and fragile. Possibly this isn't something that Django can handle with a basic single server setup but maybe there's something I'm missing.
|
# ? Aug 27, 2021 07:53 |
|
I think you mean database routing? https://docs.djangoproject.com/en/2.1/topics/db/multi-db/#automatic-database-routing though I might be getting confused
|
# ? Aug 27, 2021 12:06 |
|
|
# ? Jun 3, 2024 21:55 |
I think the question is more about having multiple different auth mechanisms / User models within a single application. I was looking into that recently to see if it was possible (i.e.to entirely segregate admin users from customer users, at the database level, for a friend who is paranoid about data exfiltration), but all the results I found googling were “don’t, that way lies madness”. Would be interested to know if there is a way, too.
|
|
# ? Aug 27, 2021 12:41 |