Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 14 2021 16:11
    @MadLittleMods banned @Rehmanjeff
Bo
@BoPeng
@matrixbot I would like to make the URLs as short as possible for users so that they can type easily. Although I can move /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.
Another way is to dispatch non-/{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.
Nam Le
@leqnam

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 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?

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

Bo
@BoPeng
@leqnam Are you referring to the hash file content question or the old versioning problem? My app has a pretty complex version structure in that users can share multiple versions of 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.
Nam Le
@leqnam
Hmm, so I think you add more field, named book_status in the Books table. then just query with status you want, Once the book is published, change the status
Bo
@BoPeng
Yes, that is what I did for "published" books because users have the same permission on them. For unpublished ones that are shared to specified groups of users and groups, I have to use a Python function to filter QuerySetwith all versions that are viewable by specific users.
Nam Le
@leqnam
yes. that's okey. so your problem is done?
Fabian Schlager
@ghtyrant

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!

Bo
@BoPeng

@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.

Rian0702
@Rian0702

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:

  • User enters something like "start" in table_1
  • a value in table_2 updates every 5 minutes
  • User enters something like "stop" in table_1
  • updating the table_2 stops

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

Ghost
@ghost~5e554ddcd73408ce4fdab57a
you can do more with pytonik MVC framework join the community https://gitter.im/pytonik-mvc/community
ganboldoo7
@ganboldoo7
Hi guys, I have a question about database column indexing.
What is the difference between db_index=True and Meta.Indexes ?
Ghost
@ghost~5e554ddcd73408ce4fdab57a
Pytonik Alpha Version 1.9.8a2 has been released out for testing, start deploying, contributing to pytonik Framework. Download and install https://pypi.org/project/pytonik/1.9.8a2/ It will Bleed your mind. star and forked https://github.com/pytonik/pytonik/
Bo
@BoPeng
What apps do you guys use for general "invitation", "review" and "approve" emails, for example for users to send content (a link) for another user to review, approve and deny? django-invitations seems to the app to use but it is in beta and there should be more stable apps for such a common feature.
QbasicFan
@QbasicFan
@BoPeng django-invitations looks solid with more than 230 starts...But looks like you will have to do some customization to send emails based on different states and privileges ...
Ghost
@ghost~5e554ddcd73408ce4fdab57a
Pytonik Alpha Version 1.9.8a2 has been released out for testing, start deploying, contributing to pytonik Framework. Download and install https://pypi.org/project/pytonik/1.9.8a2/ It will Bleed your mind. star and forked https://github.com/pytonik/pytonik/
Bo
@BoPeng
@QbasicFan Thanks. I will give django-invitations a try. I have seen such features from django apps developed before django-invitations was developed so I thought there must be some app out there that is more mature than django-invitations (beta + 63% code coverage).
Bo
@BoPeng
@QbasicFan django-invitations is actually not usable because it is designed for inviting others to join a site. Its model has only one link so I cannot even use it for two actions ("reject" and "approve"). I will continue to search for something more general.
QbasicFan
@QbasicFan
you can probably build a quick solution to send invites based on the requirements you want...
If you do make it open source, I would like to use it and contribute
Bo
@BoPeng
@QbasicFan I found django-generic-confirmation a good fit for my need, as long as it supports confirmation from another user (not sure yet). I do not understand why this app did not receive much attention though (2 watcher + 18 stars) because its concept is very general and can be applied to a lot of cases. What this app is lacking is 1) django 2.x support (there is a PR for it), 2) more doc + support (seeming no longer maintained now), 3) functions to send emails and reminding emails. I think, if there is no other good option available, I will have to fork this app to add django 2.x 3.x support, and email support (e.g. tables from 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).
QbasicFan
@QbasicFan
thanks for sharing
Bo
@BoPeng
But I still think there should be existing solutions for it, and it will not be a waste of time to evaluate more possibilities. For example, my project uses celery so I can potentially add all "pending" actions to the celery queue but not execute, and allow the notification receiver to start the task through a link from an email.
Bo
@BoPeng
Or add all the possible actions to a customized table and let 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.
El 李天宝
@elcolie
I am wonder. Why I don't find any AWS Cognitos tools that make migration files?
I am fully understand that it is not a Postgresql or local db. But why?
James Komo
@jameskomo
Who has used Django AutoComplete light especially working with two models (FK)
Nitish Kumar
@thisisnitish
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'
can anybody help me...
I'm getting error...I tried but couldn't find the solution
AlbertDavid
@AlbertDavid94
you're defining a function PostListView whereas that should be a class.
ListView is not being used as a inheritance object but as a bare arguement for your function
Nitish Kumar
@thisisnitish
ohh..thankyou @AlbertDavid94 thanks a lot... 😊
Nitish Kumar
@thisisnitish
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm

def register(request):
    if request.method == 'POST':
        form = UserRegisterForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(request, f'Your account has been created! You are now able to log in')
            return redirect('login')
    else:
        form = UserRegisterForm()
    return render(request, 'users/register.html', {'form': form})


@login_required
def profile(request):
    if request.method == 'POST':
        u_form = UserUpdateForm(request.POST, instance= request.user)
        p_form = ProfileUpdateForm(request.POST, request.FILES, instance= request.user.profile)

        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()
            messages.success(request, f'Your account has been updated!!')
            return redirect('profile')
    else:
        u_form = UserUpdateForm(instance= request.user)
        p_form = ProfileUpdateForm(instance= request.user.profile)

    context = {
        'u_form': u_form,
        'p_form': p_form
    }

    return render(request, 'users/profile.html', context)
TypeError: save() got an unexpected keyword argument 'force_insert'
I'm getting this error whenever I'm registering the new user...can anybody help me
TypeError at /register/
save() got an unexpected keyword argument 'force_insert'
this one is on the web page
Nitish Kumar
@thisisnitish
@AlbertDavid94 can you solve my problem
Saket Patel
@Samy-33
Hey guys, have any of you guys use CI/CD to deploy django app on Google App Engine?
I am not sure how I should handle ./manage.py migrate in CD
Any help is appreciated
Roel
@roelzkie15
@Samy-33 you can use fabric for your deployment automation
Saket Patel
@Samy-33
Hi @roelzkie15, App Engine doesn't allow running commands over ssh
Vishesh Mangla
@Teut2711
What are best practices to read data and add to database?
should I do it in views?
I want to make a site with links to my ds algo solved problems.
So I want to read all the file names and show it as html.
as a tag