Re: Django-Channels with 2 applications
I've seen the docs already. In fact, 3 people from my team have seen it and tried to do what I'm trying to accomplish. We're at a point where we are either missing something or the Channels is not capable of what we need. Thank you in advance for any help! segunda-feira, 4 de Novembro de 2019 às 13:47:55 UTC, Integr@te System escreveu: > > Hi Idea man, > > You can acknowlegdes and try it: > > https://channels.readthedocs.io/en/latest/ > > > On Mon, Nov 4, 2019, 19:11 Daniel Carvalho > wrote: > >> Hello! >> >> >> I'm trying to make an example to test if it is possible to have 2 >> independent django apps connected to the same channel from django-channels. >> So far, I was able to make an example running on one machine and 2 other >> machines being able to access the first via a client. But the goal is to be >> able to connect separate applications in a single channel to communicate. >> Is that possible? >> >> >> *Note*: I'm also using redis, if that helps. >> >> >> Thank you! >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django...@googlegroups.com . >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/88f3d63e-273d-4bbf-9ebe-f7ca348c7c18%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/88f3d63e-273d-4bbf-9ebe-f7ca348c7c18%40googlegroups.com?utm_medium=email_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8f24a4d8-3050-43c5-8d01-ad11d9e94c73%40googlegroups.com.
Django-Channels with 2 applications
Hello! I'm trying to make an example to test if it is possible to have 2 independent django apps connected to the same channel from django-channels. So far, I was able to make an example running on one machine and 2 other machines being able to access the first via a client. But the goal is to be able to connect separate applications in a single channel to communicate. Is that possible? *Note*: I'm also using redis, if that helps. Thank you! -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/88f3d63e-273d-4bbf-9ebe-f7ca348c7c18%40googlegroups.com.
Re: how to raise an error on django admin
I think the way to do is: from django.contrib import messages then somewhere... messages.add_message(request, messages.ERROR, "your error message") The message will be displayed in the top of the next admin page On 01/03/2011 09:40 PM, Acorn wrote: > I'd like to know this too. > > On 3 January 2011 17:25, rahul jainwrote: >> Hi, >> >> How to display an error in django admin (the error should be displayed in >> red just like in forms) >> >> Something of this form >> >> http://groups.google.com/group/django-users/browse_thread/thread/68d4ea1915654134/447ef8473cf86672 >> >> Thanks. >> >> Rahul >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-us...@googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> > signature.asc Description: OpenPGP digital signature
Re: removable file field and other features
On 12/20/2010 12:55 AM, Daniel Carvalho wrote: > Everybody knows the default django FileField doesn't allow to remove an > existing file... > > This is a good replacement. Just use RemovableFileField instead of > FileField in your models: > http://djangosnippets.org/snippets/636/ > > > I want to implement on it another feature- When there is a file being > uploaded, but the form fails validation for other reason, I want to keep > the file in the server, so no need to upload the file again. The next > time the form is submit I would take the file and save it in the model. > > > BUT this is not possible because there is (apparently) no way to acess > the request object inside RemovableFileField nor from the widget... > > SO I think I have to implement this in the ModelForm, or in the > ModelAdmin, which is a more ugly solution. > (any ideas???) > > If anyone wants to use it, I implemented this solution. Just use FilesModelAdmin for your models that have file or image fields. 1. A checkbox will be displayed, to remove the current value, if the field supports blank values. 2. The uploaded files are stored in session variables for later use, in case the form fails validation you don't need to upload then again. 3. It works for inline models also. Problem: if the user is editing two forms at the same time in the same session, the uploaded files will be mixed... # coding: utf-8 from django.contrib import admin from django import forms from django.utils.safestring import mark_safe from django.utils.translation import ugettext, ugettext_lazy as _ import django.core.files import re import tempfile, shutil from django.db import models # if we have a field called "imagem", the associated checkbox for deleting the file will be "imagem" + REMOVE_SUFFIX, "imagem__remove" REMOVE_SUFFIX = "__remove" # The session variable name we will use to store the uploaded files SESSION_NAME = "save_uploaded_files" import threading # remember the request value # so it can be accessed from any place in the thread def set_current_request(request): global local local = threading.local() local.current_request = request def get_current_request(): global local return local.current_request class FileWidget(forms.FileInput): # if this file accepts blanks or not # This will define if we put a checkbox for removing the file blank = False def render(self, name, value, attrs=None): output = [] if value: # file has a current value if hasattr(value, "url"): # the file value is the value stored in the model output.append('%s %s %s ' % \ (ugettext('Currently:'), value.url, value, ugettext('Change:'))) else: # the file value is the file uploaded in the previous request but not saved yet, because the form validation failed: output.append('%s %s %s ' % \ (ugettext('Not saved yet:'), value, ugettext('Change:'))) # If it has a current value, and the field accepts blanks, # we place a checkbox for removing it if self.blank: request = get_current_request() name_checkbox = name + REMOVE_SUFFIX # This is important to remember the checkbox state, # when the form is submited but fails validation, and is displayed again if request and name_checkbox in request.POST.keys(): checked = 'checked="on"' else: checked = '' output.append(' %s ' % (name_checkbox, name, checked, name, ugettext('Remove'))) output.append(super(FileWidget, self).render(name, value, attrs)) return mark_safe(u''.join(output)) # The same, but accepts blanks class FileWidgetBlank(FileWidget): blank = True # This ModelAdmin offers this funtionalities: # For each file or image field, keeps uploaded files in the server even if the form fails validation, so they dont need to be uploaded again. When the form is saved, the uploaded files are also saved to the model. # Put a checkbox for removing the file, it it accepts blanks. # This also works for inline models, which have to be FilesStackedInline class FilesModelAdmin(admin.ModelAdmin): def formfield_for_dbfield(self, db_field, **kwargs): # is it file or image? if type(db_field) in [ models.ImageField, models.FileField]: if db_field.blank: # accept blank? kwargs['widget'] = FileWidgetBlank else: kwargs['widget'] = FileWidget return super(FilesModelAdmin, self).formfield_for_dbfield(db_field,**kwargs) # This function is called before add_view and change_view # It saves the uploaded files, and at the same time restores previous uploaded files. def manage_up
removable file field and other features
Everybody knows the default django FileField doesn't allow to remove an existing file... This is a good replacement. Just use RemovableFileField instead of FileField in your models: http://djangosnippets.org/snippets/636/ I want to implement on it another feature- When there is a file being uploaded, but the form fails validation for other reason, I want to keep the file in the server, so no need to upload the file again. The next time the form is submit I would take the file and save it in the model. BUT this is not possible because there is (apparently) no way to acess the request object inside RemovableFileField nor from the widget... SO I think I have to implement this in the ModelForm, or in the ModelAdmin, which is a more ugly solution. (any ideas???) signature.asc Description: OpenPGP digital signature
form upload field and form validation
hi I have a form with a file upload field. If the form fails validation, the user has to give all the file fields another time. Someone told me it is possible to avoid that but I can't find more information... There was a thread about this before: http://groups.google.com/group/django-users/browse_thread/thread/c09935490a56256f/ecda5197f7f60654?hl=en=gst=form+upload+remember+field#ecda5197f7f60654 """ If you search in the archives, I seem to remember some people came up with ways to pass the filename back in any case for manual display if you want that, but it still won't be submitted as part of them form. """ couldn't find it. Anyone knows? signature.asc Description: OpenPGP digital signature
Re: doing validation in admin form
On 12/06/2010 04:18 PM, Wayne Smith wrote: > Then yes, in the clean() method of your Galeria form, you could check the > number of fotos present and then raise a ValidationError if it is too many, > along with a custom message for the user. > > Is that what you wish to do? > hi I think the "clean" method wont solve the problem because at the time it is called, the inlines from galeria have not been saved yet... This is what happen when I submit a form with a galeria and two fotografias. the methods are called in this order: 1. Galeria.clean - don't know the fotografias yet! 2. GaleriaAdmin.save_model (before calling super.save_model) 3. Galeria.save ( before calling super.save) 4. galeria presave signal 5. galeria presave signal 6. galeria postsave signal 7. galeria postsave signal 8. Galeria.save ( after calling super.save) 9. GaleriaAdmin.save_model (after calling super.save_model) 10. Fotografia.save - first foto - only now the fotos are saved... 11. Fotografia.save - second foto So it seems if someone wants to execute some code after all the form has been processed, he has to do that somewhere else. [ Maybe in the form submit view? ] Anyway if I want to perform a validation there, it is to late. Maybe the only solution would be to do that in the GaleriaAdmin.save_model, and have to see the request parameters to know how many new files have been uploaded... signature.asc Description: OpenPGP digital signature
Re: doing validation in admin form
On 12/06/2010 03:05 AM, Wayne Smith wrote: > It's hard to say, because I don't know what kind of "validation" or business > logic regarding it you are trying to accomplish/employ. > suppose I want a validation like this: the number of fotos in a galeria should be limited to a number, which depends on the user that created it (OR, depends on some values that are in the galeria object) > However, if you are wanting to ensure you validate a foto during a gallery > save, why not call an overridden fotos.save() from your custom > galeria.save()? > signature.asc Description: OpenPGP digital signature
doing validation in admin form
hi I have this models: models.py: class Galeria(models.Model): ... class Foto(models.Model): ... galeria = models.ForeignKey(Galeria, null=False) admin.py: class FotoInline(admin.StackedInline): model = Foto class GaleriaAdmin(admin.ModelAdmin): inlines = [FotoInline, VideoInline] admin.site.register(Galeria, GaleriaAdmin) When a galeria is saved in the django administration, I want to perform a validation that involves his fotos. .. They are edited at the same time because I use inline in the admin. But cannot do that in Galeria.save, nor GaleriaAdmin.save_model, nor in a postsave event from galeria, because at the time it is called the fotos have not been saved yet. Where should I do it the validation? Have to define a GaleriaForm and do something there? signature.asc Description: OpenPGP digital signature
list_display with a function
hi I have a model that defines a function: class Test(models.Model): name = models.CharField(max_length=200) data_expira = models.DateField() def expired(self): return self.data_expira < datetime.date.today() expired.short_description = 'Expirou?' I want to put it in list_display for this model: list_display = ["name", "expired"] BUT django admin displays it as a text, "True" or "False"... can I tell django that it is a boolean field? signature.asc Description: OpenPGP digital signature
no such class TextArea
Hi, I want to define a form with a multi-line textfield. from django import forms class TesteForm(forms.Form): field1 = forms.CharField( max_length=100,widget=forms.widgets.TextInput()) ... field2 = forms.CharField( widget=forms.widgets.TextArea(attrs={'cols': 40,'rows': 5})) But it gives the error 'module' object has no attribute 'TextArea'!! If I do pydoc django.forms.widgets.TextArea and it also says there is no such class TextArea... what is happening here? I have django 1.2.3 and python 2.6... signature.asc Description: OpenPGP digital signature
arbitrary ordering in a model
Hi I have some models where I want objects to be displayed in an arbitrary order. For that I have in the model a number field, which is used to sort. class MyModel: ... class Meta: ordering = ["orderfield"] It would be cool if instead of editing this field, I have a "go up" and "go down" button in the django administrator, to easily sort the objects. Anyone know a django app for that? signature.asc Description: OpenPGP digital signature