Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Permission: All new users have permissions to everything. Why? [2.0]

First off: I'm new to webdev, and learning Django for funsies. I've been programming for about 2 years.

I have a group, 'employee' that has add/edit/delete permission on model 'tour'.

However, you can add/edit/delete tours without being in the 'employee' group.

This is a pretty barebones project, and I just started adding auth stuff (using basic vanilla Django-official-documentation-2.0 auth features).

I know how to remove permissions, but I feel like I'm missing a piece of information bigger than that.

Why are all users defaulting to have these permissions? What's the point of adding permissions to groups when they've already had them on default?



[**Solved!**](https://www.reddit.com/r/django/comments/881rl2/permission_all_new_users_have_permissions_to/dwh7ktd/) I'm a dummy.
> The admin checks the permissions automatically but in Your own views You have to check the permission explicitly. /u/old_faraon

/r/django
https://redd.it/881rl2
How To Create a Flask RESTful API with Unittest Without A Database?

Hello guys,

I'm wondering, is there a way to create a Flask API and write a unittest for GET, POST, DELETE and PUT without integrating a database and instead test them out using classes? All the examples/tutorials I'm finding they're all using a database like Postgres, Mong DB etc...

I'm completely new to this concept as I have never created a web app or anything similar. I just know the basics of Python and that's about it. So, how can I write a Flask app in a TDD way without utilizing a database? This is all for a test project assignment I have been given.

/r/flask
https://redd.it/888lbu
Adding commenting capabilities to Wagtail 2, any suggestions?

Hi All, am working on a new blog site in Wagtail, and i wanted to make sure it had a moderated commenting feature. I was wondering if that's baked into Wagtail, or as an app (haven't found any yet).

I've used [isso](https://posativ.org/isso/) before, and that's been solid, but i'm curious if any well-done integrations already exist that you have used or know about.

Thank you,
m


/r/django
https://redd.it/88b2qk
[D] Preventing Triplet networks from collapse

What are your strategies for preventing collapse in triplet networks \(for metric learning tasks\)?

Things that I have tried:

* Semi\-hard negative mining.
* Hard negative mining, with progressively increasing batch size \(so the network doesn't see too hard of a loss too early\).
* Distance weighted negative mining \(from the \[Sampling Matters in Deep Embedding Learning\]\([https://arxiv.org/abs/1706.07567](https://arxiv.org/abs/1706.07567)\) paper\).

Anything else that comes to mind? Any strategies that you have used \(either sampling, or otherwise\) to prevent collapse?

/r/MachineLearning
https://redd.it/88by8i
How to dynamically show/hide a fieldset in django admin?

Please excuse me if this is an obvious question but I've been going around in circles on this. I wish to expand a fieldset only if a certain boolean field is True and am not sure how to achieve this in admin.py. Here is a simple example:

# models.py
class MyModel(models.Model):
field1 = models.CharField(max_length=45)
field2 = models.CharField(max_length=45)
field3 = models.CharField(max_length=45)
field4 = models.CharField(max_length=45)
reality_check = models.BooleanField(default=False)

#admin.py
class MyModelAdmin(admin.ModelAdmin):

XXXX = "collapse"
if obj.reality_check == True: # <<-- How do I achieve this ?
XXXX = "open"

fieldsets = (
('Set 1', {'fields':('field1', 'field2', 'reality_check',)}),
('Set 2', {'classes': (XXXX, ), 'fields':('field3', 'field4',)}),
)

/r/django
https://redd.it/88d5hz
Possible to have *inline* interactive plots in Jupyterlab?

Hi, just started with Jupyterlab and it's great but I had a quick question. Is it possible to have interactive plots in Jupyterlab (e.g., a 3D scatterplot made in Matplotlib that you can can rotate in, zoom, etc.) be inline, rather than open in a new window? Not a huge deal if not, just curious.

/r/IPython
https://redd.it/88dtto
Using Ajax to send form data to Django view

I want to use selected value from the template to filter data in months but keep getting 403 (Forbidden) error. Here are my files:

Models.py
class FuelOperation(models.Model):
date = models.DateField(default=datetime.date.today)
liter = models.IntegerField()

Template.html

<form id="month-form" method="post">
{% csrf_token %}
<select id="month-select" class="selectpicker">
<option value="03" name="March">3</option>
<option value="04" name="April">4</option>
</select>
</form>


Javascript

$("#month-select").on("change", function(){
var selectedValue = $(this).text();

$.ajax({
url : "{% url 'index' %}",
type : "POST",
data : {"value" : selectedValue},
dataType : "json",
success : function(){

}
});
});


views.py

def index(request):
if request.method == 'POST':
key = request.POST.get('value')
operations = FuelOperation.objects.filter(date__month=key)
context = {'operations': operations}
return HttpResponse(simplejson.dumps({"success": "true"}, mimetype="application/json"))

return render(request, 'fuel/index.html', context)

urls.py

path('', views.index, name='index'),



And I hope my code formatting appears good because it's my first
time posting so...

/r/django
https://redd.it/88f107
[AF] Flak web app to find amenities (like toilets) near you?

I am learning Flask. So I want to build a web app that will allow users find amenities (like toilets) near you! It will show toilets within walking distance. User can then use Maps to find walking directions to the amenity.

What tech stack will you use to design and build this web app?

Please recommend me some tutorials.


/r/flask
https://redd.it/88bhc1
[P] TensorFlow's eager execution is an imperative programming environment that evaluates operations immediately, without an extra graph-building step.
https://www.tensorflow.org/programmers_guide/eager

/r/MachineLearning
https://redd.it/88cslg
Hello, I'm new to Django and I'd like to know what you've been doing with it

Hey, people! I've recently been taking a look at the Django docs and after doing the basic tutorial it looks like an amazing tool to rapidly develop websites, so I've got curious about what else other people are using Django for. Nowadays I'm mostly doing microservices and REST APIs with Node.js on AWS, wiring them together with queues. I wonder if would be possible to write apps with a similar architecture taking advantage of all the goodies that Django offers out of the box.

/r/django
https://redd.it/88b7cg
No matter what I do, I cannot get the favicon to display

It used to work, but just suddenly stopped. I tried changing the picture, to setting it up in the urlpatterns and even hardcode it into my Nginx to find my favicon but it just doesn't work.

When I inspect element in chrome the link to the favicon works fine.

Have anyone had this issue before??

Getting favicons to display right have never been an issue.

This is my website btw
https://southafricans.online/

/r/django
https://redd.it/88habp
Advice on hosting a new project

I'm launching a new project, and as I look at Heroku & AWS, I'm wondering if there is a better/cheaper alternative out there that I haven't looked at.

With Heroku, I'd be using:

* Hobby Dyno to start
* Standard Postgres DB (will have millions of rows)
* Logging
* Caching on the front end
* Scheduler for running daily processes

As you add more features/"Add-ons" and traffic to your app grows, Heroku gets unnecessarily expensive.

Is AWS the best option?


/r/django
https://redd.it/88b89l
Django Multi user type design layout?

So I have a Django app and I have Multiple users. I have a extension of the 'AbstractBaseUser' called User. When a user is created they either can choose 'Banker' or 'Individual'.

When searching for users on my app I wanted to be able to fetch the profile information from both classes. I'm going to be using 'Serializer relations' from the DRF.

How should I layout the models to allow easy fetching? Should I have a OneToOne Field in the user class to the corresponding user type? Or should I have a user field in the 'Banker' and 'Individual'?

I'm just very confused on the right way to layout the model in a professional matter.

/r/django
https://redd.it/88bl98
Moved secret_key location on fresh install and now homepage is 404

I have just been playing around in Django2 and setup a new install on Ubuntu EC2 instance, I then realized the secret key was still in the settings file so I moved it to a text file in /etc and then the standard Django homepage became a 404 but even after restoring the secret key it didnt change back. Whats also strange is that the basic /blog I had made works fine still as does /admin. I have made no other changes to the urls or other structure and the homepage was fine after making the /blog until I moved the secret key....

/r/django
https://redd.it/88aphe
Flask data from mysql fails to send data occasionally.

When I add data to the current_user model (lets say I add api keys to the user model), and the user updates these. When I try to retrieve that new data flask fails to send the new data about 50% of the requests.

Why would updating the user model while logged in cause the new data to not be returned 50%? If I reboot the server all the data will return 100% of the time .

Hints: This does not appear to happen when not using SSL and connecting directly to gunicorn.



/r/flask
https://redd.it/87v2a2