good architectural design
but in the same time I would like to keep "permission" and "logistics" orthogonal so that the query will always return the correct latest versions no matter how the logistics change.
Building wheel for Pillow (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /Users/username/Documents/Practice/Other/project-website/project-env/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-_jgvipfu/Pillow/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-_jgvipfu/Pillow/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/tmp/pip-wheel-uyjkgaxw
cwd: /private/tmp/pip-install-_jgvipfu/Pillow/
Complete output (144 lines):
sudo python3 -m pip install -r requirements/local.txt
char
fields filename
, filecontent
(hash value) to refer to a file, where the content is saved separately according hash values in a shared location. In this way renaming files, uploading files with the same content will not result in new file content. I feel that this could be a very common approach for repository-like applications. Does anyone know an existing app or example that work in this way?
Brett Jackson
> <@gitter_bopeng:matrix.org> How to I prevent users from registering user names such as user
, users
, about
, and login
? I have URL /{user_name}
mapped for users so these usernames could conflict with system URLs (/about
will not work even if a user successfully registers about
as a user name). I even want to disallow names such as fxxk
. I could list all names in clean_username
but I am wondering if there is an existing approach.
Bo, could you mitigate that by placing your other routes above the /{user_name}
route?
/users
from all_auth
to /~users
, having a user named /users
will still be confusing. I came across https://github.com/dsignr/disallowed-usernames/ and added the list to UserCreationForm.clean_username
.
/{user_names}
to admin.mycompany.com
using django-hosts but it might be an overkill and does not really solve the problem of mycompany.com/users
even if the real users
URL is admin.mycompnay.com/users
.
To avoid storing multiple copies of the same file (from multiple objects the files belong or multiple users), I would like to separate filename and file content in handling user-uploaded files. That is to say, the model will use two
char
fieldsfilename
,filecontent
(hash value) to refer to a file, where the content is saved separately according hash values in a shared location. In this way renaming files, uploading files with the same content will not result in new file content. I feel that this could be a very common approach for repository-like applications. Does anyone know an existing app or example that work in this way?
Hmm. Why don't you create a new Model called BookVersion that will store histories of books (One-to-Many)? Then, fillter them with the Book Id
Book
to selected invitees and groups so that everyone sees a different set of versions. For example, a "work in progress" versions could be shared with group members, and "published" versions could be shared to all visitors. What you suggested seems to like a Model for Book
and a one to many relationship to multiple versions of the Book, but I still cannot figure out how to get the most "viewable" version for each user using these two models.
I have some issues with Django migrations, and I'm not sure if it's intended behaviour or a bug. I have two migrations, one adds a new permission to a model, the next runs Python code to look up a group and gives that new permission to this group:
class Migration(migrations.Migration):
dependencies = [
("gallery", "0023_gallerypermissions"),
]
operations = [
migrations.AlterModelOptions(
name="gallerypermissions",
options={
"default_permissions": (),
"managed": False,
"permissions": (
(
"manage_reference_shots",
"Manually upload and remove reference shots.",
),
),
},
),
]
def add_permission(apps, schema_editor):
Group = apps.get_model("auth", "Group")
Permission = apps.get_model("auth", "Permission")
group = Group.objects.get(name="Regular")
group.permissions.add(Permission.objects.get(codename="manage_reference_shots"))
group.save()
def remove_permission(apps, schema_editor):
Group = apps.get_model("auth", "Group")
Permission = apps.get_model("auth", "Permission")
group = Group.objects.get(name="Regular")
group.permissions.remove(Permission.objects.get(codename="manage_reference_shots"))
group.save()
class Migration(migrations.Migration):
dependencies = [
("gallery", "0024_auto_20200226_1059"),
]
operations = [migrations.RunPython(add_permission, reverse_code=remove_permission)]
Now, if I run those migrations separately, all works well. If I simply run migrate
, it fails due to the second migration not being able to find manage_reference_shots
in the database. I kinda understand this, as all migrations run in the same transaction (is there a way to run them in separate transactions, without doing so manually from the command line?).
What I don't understand is: The first migration is marked as done, even though the permission is NOT in the database afterwards!
@leqnam Not really. I am doing something like
def get_queryset(self):
books = Book.objects.filter(by self.kwargs['user'])
return [x.id for x in books if is_latest_version(x, books)]
with the risk of fellow workers calling get_queryset().filter()
later so I am still hoping for a SQL/ORM solution, or something like return QuerySet(instance_list)
that can be filtered
upon.
Hello everyone,
is it possible to run something like a cron job when a model is saved? And to stop that too?
The goal is:
is that even possible with django? I read about celery but this has to be triggered by a command line if i did not get this wrong
django-email-confirmation
), and I might have to rename it (e.g. django-deferred-form
so that it can be released and used in my application (right now I have to install git
to use its github version).
django-email-confirm-la
confirms them. The last commit for this package is 3 years ago and it does not support django 2.x though.
from django.shortcuts import render
from django.views.generic import ListView
from .models import Post
#from django.http import HttpResponse
def home(request):
context = {
'posts' : Post.objects.all()
}
return render(request, 'blog/home.html', context)
def PostListView(ListView):
model = Post
template_name = 'blog/home.html' # <app>/<model>_<viewtype>.html
context_object_name = 'posts'
ordering = ['-date_posted']
def about(request):
return render(request, 'blog/about.html', {'title' : 'About'})
from django.urls import path
from .views import PostListView
from . import views
urlpatterns = [
path('', PostListView.as_view(), name = 'blog-home'),
path('about/', views.about, name = 'blog-about'),
]
path('', PostListView.as_view(), name = 'blog-home'),
AttributeError: 'function' object has no attribute 'as_view'