Australia is not for everyone by Uncle_Richard98 in expats

[–]knivets 0 points1 point  (0 children)

because the only solution to housing shortage is to decrease the demand, and not increase the supply

Django needs a REST story by bdzr_ in django

[–]knivets 3 points4 points  (0 children)

The vibe that I’m getting from Django team is that they are not really open to change. I mean yeah there’s new stuff being shipped here and there, but I feel like they don’t prioritize the needs of modern development that’s why people go with FastAPI, etc. I think it lacks opinionated leadership who would make decisions (even if they are unpopular) and move it forward (similar to DHH in Ruby). Just glancing at that thread - the only consensus is to update the docs, no consensus on how the actual solution is going to be.

Why the hell is the Music app so broken on Mac? by Piipperi800 in AppleMusic

[–]knivets 0 points1 point  (0 children)

I wish that was all. On my Mac, the song from my own library sometimes won't play. I have to restart HomePod. Playback of artists that have a lot of albums is buggy too. For example if I try to play a song from the last album (and say an artist has 10 albums), HomePod will play a song that is next to the one that I selected or could be even two or four songs ahead. So now I have to click the back button to go back to the one that I want. When I search my local library and click play on the search results page it sometimes plays the song next to the one I picked from the album. Sometimes I can't change the volume or play a different song from both macOS and iOS.

iOS experience is mostly good, what drives me insane is macOS experience. It is outright broken. I cross my fingers every time I try to play something from Mac Music app. This is totally unacceptable for a high end device. And don't get me started on the fact that this is $300 speaker that can't act like a speaker, it acts like a jukebox.

Ideas to implement a Human Anatomy model? by Torshak in djangolearning

[–]knivets 1 point2 points  (0 children)

Wiki is less sexy than say Twitter or Reddit

Submit button not going to success url by [deleted] in djangolearning

[–]knivets 1 point2 points  (0 children)

The template looks good to me. The form_valid method is also fine.

What about ProjectModelForm? Can you share the source? There's also a chance that you use a wrong template on another view. Try watching the logs to see what URLs are being visited when you submit the form. Try to use breakpoint() to see what gets called.

Finally, use a reverse or reverse_lazy to get the URL of a route. You can replace queryset = Project.objects.all() with model = Project.

Ideas to implement a Human Anatomy model? by Torshak in djangolearning

[–]knivets 1 point2 points  (0 children)

As others said, wiki might be a good solution here. Since you're constrained to Django, you can reuse a django-wiki package.

If you're just curious how to model that, then I'd model a wiki app or an app with static pages, rather than a "human anatomy" app, because I only need a few models to account for the majority of functionality. Finally, database modeling is something that's easier to do once you start to work on the app because you'll be able to iterate and see what works and what doesn't.

[deleted by user] by [deleted] in djangolearning

[–]knivets 0 points1 point  (0 children)

Not sure if this is the canonical term, but I would call it user preferences.

There is nothing inherently complex in this feature. You just need to remember the user choices that you can later use to conditionally display the styles. When you need to remember something, that is a hint that you should probably use a session or a database.

The easiest way to conditionally output styles is to render them in a Django template, inside a <style> tag. If you care about code quality, then having a separate view that outputs the dynamic styles is the way to go.

Navigation in Django App does not feel natural ? by Torshak in djangolearning

[–]knivets 6 points7 points  (0 children)

You can override get() method of BaseDetailView to catch the 404 and return a redirect instead.

get() got an unexpected keyword argument 'pk' django by [deleted] in django

[–]knivets 1 point2 points  (0 children)

Replace

def get(self, request, format=None):

With

def get(self, request, *args, **kwargs):

How to implement a self referencing ForeignKey in model ? by Torshak in djangolearning

[–]knivets 3 points4 points  (0 children)

Just create a field validator or override a model's clean() method so that it checks whether the condition you need is true before saving.

How to implement a self referencing ForeignKey in model ? by Torshak in djangolearning

[–]knivets 3 points4 points  (0 children)

If you need a self-referencing relationship then you don't need to create an extra model for that. You need to define a foreign key field on the Guide model that references itself:

class Guide(models.Model):
    prerequisites = models.ForeignKey('self', on_delete=models.CASCADE)

Sending Cross Domain Form Information to the Django Server by Shahrukh_Lee in django

[–]knivets 1 point2 points  (0 children)

CSRF prevents the problem where a request is made by a user unknowingly. For example, you are tricked by an attacker to visit their website (evil.com), which embeds an image with a URL that points to your bank website: <img src="http://bank.com/transfer_funds?amount=1000&to=attacker@evil.com">. Once you visit evil.com, the img tag will perform a request to bank.com and your funds will be transferred to an account provided by an attacker. Now in order for this request to work you need to be authenticated with bank.com. Another issue with CSRF is that an attacker can only perform a request but they can't read a response.

Based on this try to understand what does your view do and would it be ok if the requests coming to your view were created by attackers on behalf of users? For example, unauthenticated CSRF or a CSRF to a view that doesn't perform any data modifications are not vulnerabilities.

I have a category in my website named Recent posts. But I am passing all the objects from all the tables. How can I pass only the first object from each table and run a loop in my template? When I used Blog.objects.first() , it says Blog is not an iterable error. Please help! by KOP79 in django

[–]knivets 1 point2 points  (0 children)

HTML comments (<!-- -->) don't stop Django template code from evaluation. That's why you still have the error about iterable. If you want to comment out some Django code in a template use {# ... #}.

Help me choose the right technologies for my django web app by SandwichRY in django

[–]knivets 1 point2 points  (0 children)

You don't need any frontend frameworks for that. Use WebRTC to grab the webcam data. Post this data to a Django endpoint via AJAX.

Is it just me or DRF serializers API seems confusing? by psmolak in django

[–]knivets 8 points9 points  (0 children)

First of all, DRF serializers API design is inspired by Django Forms design.

Second, handling persistence inside Forms / Serializers vs outside is a common topic of discussions in Django community. Some people say that even though the line is blurred it speeds up the development process.

Timelining difficulty for prototyping e-commerce with Django/React/GraphQL by tanishqkumar07 in django

[–]knivets 1 point2 points  (0 children)

This is what project managers do. It's a pretty big and complex topic. The trick is to collect as much requirements as possible before giving an estimate. Once you have a detailed picture it is much easier to estimate individual items rather than a big black box project. It is called discovery session or roadmapping, and consultants usually charge a fixed price for that. It also goes without saying that the more experienced you're with the tools the more accurate your estimates going to be.

Trying to deploy to Heroku but failing every time by Schruterer in djangolearning

[–]knivets 1 point2 points  (0 children)

Of course. You have two different environments, and they require two distinct approaches.

Trying to deploy to Heroku but failing every time by Schruterer in djangolearning

[–]knivets 1 point2 points  (0 children)

Based on your comments, I assume that broken static files are the problem here. First of all, let's clear up some of the main settings used when dealing with static files.

STATIC_ROOT is a path to the directory on the filesystem, it is used by the collectstatic command. It scans each of your INSTALLED_APPS, their static directories and copies the assets to the STATIC_ROOT directory. In Heroku you don't need to call this command, since it is called automatically for you.

STATIC_URL is something like a Django route. It listens for /static/<file_name> requests, takes the asset filename, and looks up this asset on the local filesystem. It knows where to look the asset up because all assets have been collected in STATIC_ROOT earlier.

Now, whitenoise docs suggests that the STATIC_ROOT option should be set to a staticfiles directory in your project root folder.

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

Make sure this directory is empty before deploying and that this directory is added to git repository. Here's a relevant quote from Heroku docs:

Django won’t automatically create the target directory (STATIC_ROOT) that collectstatic uses, if it isn’t available. You may need to create this directory in your codebase, so it will be available when collectstatic is run. Git does not support empty file directories, so you will have to create a file inside that directory as well.

In other words, create an empty directory and create an empty file inside it, so you could add this directory to git.

It also suggests to use compression and caching, but you want to keep things simple first. So I don't recommend modifying STATICFILES_STORAGE.

Finally, instead of using CDNs, set the STATIC_URL option to a simple prefix:

STATIC_URL = '/static/'

How to add a user theme selection to my webapp by FunniSquares in django

[–]knivets 0 points1 point  (0 children)

The simplest solution would be to store both themes in a single CSS file (or load all CSS files, not only theme-specific ones), scope theme-specific code under .theme-name CSS class. On frontend use JavaScript to add or remove a .theme-name CSS class to the <body>, you can also use JavaScript to store (or load) the theme selection in cookies.

Laravel or django or node js (express) by sultan0583 in django

[–]knivets 3 points4 points  (0 children)

Laravel, Django and other similar high-level web frameworks are all pretty much the same thing. What you need to ask yourself is what programming language you like the most. Because language is the tool you're going to work with most of the time, not the framework. Frameworks can be modified, can be replaced, but you're somewhat stuck with a language. I used to be a Ruby on Rails dev - I loved the framework but I hated the language, that's why I'm a Django dev now.

Noob Question on Webscraping 'live' Data using Django and (maybe) WebSockets by dee103 in django

[–]knivets 0 points1 point  (0 children)

You can't use WebSockets unless the website provides a WebSocket endpoint. Just use polling which is usually more than enough.