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
help with InlineModelAdmin

I am new to Django but I am absolutely loving it. I'm using Django 1.11.2 and I am trying to add an interface for the admins to edit instances of a model associated by a foreign key to a "parent" model. The parent model is a "session" which can contain one or more "scans" that were collected that session.

I am trying to use the [InlineModelAdmin](https://docs.djangoproject.com/en/1.11/ref/contrib/admin/) feature to achieve this.

I think I made the necessary additions, but cannot see the inline model thing when I go to the Admin view and go to the screen labeled "Change session." I am pretty sure I'm missing something, but I'm not quite sure what it is.

In my app's *models.py* I have


from django.db import models

class Session(models.Model):
session_status = models.CharField(choices=SESSION_STATUS,default='Unknown',max_length=25)

class Scan(models.Model):
session = models.ForeignKey(Session, on_delete=models.CASCADE)
scan_status = models.CharField('Status',max_length=20,choices=STATUS,default='Acquired')


In my app's *admin.py* I have


from django.contrib import admin
from .models import Session
from .models import Scan
admin.site.register(Session)
admin.site.register(Scan)

class ScanInline(admin.TabularInline):
model = Scan
class SessionAdmin(admin.ModelAdmin):
inlines = [
ScanInline,
]


Sorry if this is a stupid question. But that's where I'm at:) Where else do I need to add code/information?

Thanks in advance!





/r/django
https://redd.it/6l9g6a
What to do about a newly acquired Python package?

Hi, so I recently acquired a package that's listed on PyPI. It has a git repo, but the original author is no longer maintaining it. I intend to go in and resolve the open issues and possibly make other improvements. What should I do about the git repo, though? Should I continue maintaining it on the original author's repo or should I maintain it on a fork and update the PyPI page? I have push access to the original repo and PyPI, of course.

/r/Python
https://redd.it/6lbew8
Looking for advice on basic django website.

Hello djangolearning,

I have been learning python for the past few months and wanted to try django to build a simple website.

I have gone through a few tutorials but wanted to get some advice on the following.

This website will be to track athletes progress through 6 weeks of training. For this I have decided I need to do the following.

Accounts App; one for coaches and one for athletes.

* registration with email or phone validation (integrate twilio API)

* six week view for individual athlete (only athlete can view their own progress and edit week 2-5 forms)
* list of athletes for coaches and 6 week view of athlete progress (coaches can click on any athlete to view and enter their progress week 1-6)

So here is my question, based on the other tutorials I've seen, their examples are based mostly on admin rights to edit blogs and visitors can view but make no changes.

What do you recommend I read up on to ensure that both coach and athelete can make changes to an athlete's profile/week entries, but not let athlete view other athletes profile/ week entries?

How do I ensure that both admin and athlete can make changes but athlete cannot make changes to week 1 or week 6 forms?

I have a decent idea but before I start I want to read up a little more and not sure where to find those specific tutorials or application features.

and lastly, I read somewhere that sqlite3 only allows for one change at a time. Therefore, if I have two or more atheletes/coaches submitting forms at the same time, there may be some results in errors. How do I go about this?

I'm I over my head or am I over complicating it?

Eventually I will add other apps like, statistics, charts, comments, and social media buttons... but for now, just the basics.

Thanks for the recommendations!


/r/djangolearning
https://redd.it/6l27bd
Django Form Widget Errors

The error I get is: `'MultipleChoiceField' object has no attribute 'is_hidden'`

The following is my form:

class SlackUserForm(forms.Form):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super(SlackUserForm, self).__init__(*args, **kwargs)
self.slack_access_token = get_access_token(self.request.user, 'slack')
self.channels = get_slack_channels(self.slack_access_token)
self.fields['channels'].widget = forms.MultipleChoiceField(choices=tuple(self.channels,))

family_name = forms.CharField()
given_name = forms.CharField()
primary_email = forms.EmailField()
channels = forms.MultipleChoiceField()

class Meta:
fields = ['family_name', 'given_name', 'pimary_email', 'channels']

If anyone has any idea how to fix this please let me know as I've been on it for a day now :(

/r/django
https://redd.it/6lc19b
Has anyone successfully managed to get "Download as PDF" working on Jupyter Notebook?

I've installed pandoc and texlive-xetex on my vps but still it comes up with 500 server errors when I try to download an ipython notebook as PDF

/r/IPython
https://redd.it/6lcmew
Can I simulate events with Python?

(Solved)

Is there a way to simulate events like a keypress or a mouse click using Python, by example to write text on another app, or to play a game?

/r/Python
https://redd.it/6lcwnr
Could someone help with python networkprograming?

i will change to learnpython category sorry wrong category to write

/r/Python
https://redd.it/6ldcyp
Flask newbie. Why can't Flask find my module?

from database_manager import DatabaseManager
from flask import Flask
app = Flask(__name__)


@app.route("/")
def hello():
db = DatabaseManager()

users = db.get_users()

text = ""
for user in users:
text += user["first_name"] + "<br>"

return text

The above returns a "no module named database_manager" error. database_manager.py is in the same directory.

/r/flask
https://redd.it/6lbpts
Jupyter notebook closing immediately on startup

When I try to open jupyer notebook, a window opens and then immediately closes. I installed via the anaconda package.

/r/IPython
https://redd.it/6ldusm
Top 250 Subreddits that /r/Python users are active in (ranked by deviation from the average redditor)

/r/Python
https://redd.it/6leaqy
What tips and tricks do you guys use for your Django admin panel?

I was reviewing awesome django's admin panel section while re-thinking my admin panel features and workflow and was curious to see if I couldn't pick up some new ideas.

So, I went over to [awesome django](https://github.com/rosarior/awesome-django#admin-interface) and looked at their list. It seems admin panels have come a long way since I last checked out admin add-ons.

I'm thinking of trying out a plugin or two (maybe jet or grappelli), though I know django people are usually pretty creative with their own solutions and keen on making a solid workflow. All that said, what have you guys done to make your admin panels work well for you? Do any of the plugins do the job, or did you modify them to?

/r/django
https://redd.it/6ld29e
I thought It was going to be simple...

I'm currently starting the website and I am having issues best deploying user models.

I know that django has a built in user model but I still reading over the docs and trying to understand. There are very few examples so I find it difficult to relate to my project.

I don't want any of my users to have the django admin access. I just want for three user groups, (SuperUser:me, Coach:can view and change athelete profiles, and athletes:can change some profile attributes.

This is how I am thinking about modeling it:

from django.db import models
from django.contrib.auth.models import User

class Coach(models.Model):
user_rec = models.ForeignKey(User)
first_name
last_name
email_address
phone_number
not_active

class Athlete(models.Model):
user_rec
first_name
last_name
email_address
phone_number
reg_date
week_one_start_date
not_active

class AthleteBio(models.Model):
user_rec
age
height
weight
body_fat

The next app would be a 6 week template where the user or coach clicks on the week and enters Weight, and Body fat each week. The reason I need a coach group vs Athlete group is because the coach is the only one that can enter data for week 1 and 6 (athlete can see it) and Athlete can enter data for weeks 2 through 5.

So I'm trying to create a user model that ensures that coaches has all viewing and data entry rights and athletes can only view their own data and enter only on weeks 2-5.

I thought this was going to be super easy looking at tutorials since they always explain and everything makes sense.... but now that I'm at the wheel... I'm not sure how to connect the dots.

Would anyone be interested in helping me out?

Edit: I have looked at the docs for the class models.Permission but still not sure how to integrate it.

/r/djangolearning
https://redd.it/6li2n2
Does anybody know how to get a plotly widget to run in offline mode?

This is the example from their website:

import pandas as pd
import plotly.plotly as py

from ipywidgets import widgets
from IPython.display import display, clear_output, Image
from plotly.graph_objs import *
from plotly.widgets import GraphWidget

# define our widgets
g = GraphWidget('https://plot.ly/~kevintest/1149/')
w = widgets.Dropdown(
options=['red', 'blue', 'green'],
value='blue',
description='Colour:',
)

# generate a function to handle changes in the widget
def update_on_change(change):
g.restyle({'marker.color': change['new']})

# set a listener for changes to the dropdown widget
w.observe(update_on_change, names="selected_label")

display(w)
display(g)

This doesn't run for me at all, only the drop down appears, but no graph.
How would one go about creating a dropdown widget in offline mode? There don't seem to be any real examples with the plotly package.

/r/IPython
https://redd.it/6lf01l
[HELP] My details page isn't shown, why?

Hi, people. I'm a beginner Django developer so sorry if it's a basic question.

I have a webpage that shows a list of movies and each movie has a details view, but for some reason, the details view is never rendered.

#views.py

def index(request):
latest_movies = Movie.objects.order_by('-movie_id')[:5]

template = loader.get_template('ytsmirror/index.html')
context = {
'latest_movies' : latest_movies,
}

return HttpResponse(template.render(context, request))

def detail(request, movie_id):

movie = Movie.objects.get(movie_id=movie_id)
template = loader.get_template('ytsmirror/details.html')

context = {
'movie' : movie,
'plot': 'Lorem impsum',
}

return HttpResponse(template.render(context, request))

And my urls.py

#urls.py

from django.conf.urls import url

from . import views

app_name = 'ytsmirror'
urlpatterns = [
url(r'$', views.index, name='index'),
url(r'^(?P<movie_id>\d{4})$', views.detail, name='detail'),
]

When I try to reach /ytsmirror/4200/ for example, I don't get any error and Django apparently reaches the correct URL pattern but doesn't render the details view, it stays on the index view, without any change.

What am I doing wrong?

/r/djangolearning
https://redd.it/6lhjxy
Do you mix Vue.js templates with Django templates?

So there was this [Vue.js intro video](https://www.youtube.com/watch?v=C7oiYr4_NdU&feature=youtu.be&t=5m56s), and it showed a template with the usual Django tags (e.g. `{% %}`) with Vue.js mixed right in, so the Vue.js delimiters were set to `[[ ]]` to avoid conflicts. Is this a widely-used practice?



/r/django
https://redd.it/6lk02b
[D] Is training a NN to mimic a closed-source library legal ?

Let's imagine the following situation.
John has access to the binaries of a closed source library that computes some nice image filtering, which means that he can apply it to any input image.
Now he would like to get rid of the dependency on this library and have his own filter but does not have time to do all the research, so he trains a regression CNN (that produces filtered images) on a dataset which he creates by considering a lot of images, and - as a ground truth - the output of the library on such images.

Do you have any insight on where this stands from a legal point a view ? Is it considered as IP infringement, or maybe reverse-engineering ? Does it only depend on the license agreement of the closed-source library ?

/r/MachineLearning
https://redd.it/6lk6cu
[R] Main recommendation system algorithms and how they work
https://blog.statsbot.co/recommendation-system-algorithms-ba67f39ac9a3

/r/MachineLearning
https://redd.it/6lm529