How to prefill certain fields in a new form with respect to the object detail in view in django
I am rendering a form inside a shop detail
My form fields includes name, address, shop, booking_date
I want to render the form inside of the object detail with only the shop name already prefilled because its inside of the shop detail the form is in
See also questions close to this topic
How to append a integer iteration into a string in python?
So this is my problem:
first I iterate
for i in range(1,21): print (i)
then I have a variable basename="Station"
I want a result where the output is Station_1.txt, Station_2.txt etc.
I managed to add the "_" to the variable basename like
mylist1 = ("_") s = (basename) for item in mylist1: s += item
but now I have the problem on how to get the iteration on top of the variable basename, I could get is as it own like "Station_, 1, Station_, 2" but not inside the string itself.
Sorry, a total beginner here :)
Python: number of words in line
I have a file with a lot of lines. I need to count the number of words only in line 35. Is there an easy way to do so?
"'ReverseManyToOneDescriptor' object has no attribute 'all'"
I found the answer myself, but thought that the question might benefit others:
i got the following error whenever i called:
Error: "'ReverseManyToOneDescriptor' object has no attribute 'all'"
class Schema(models.Model): label = models.TextField() description = models.TextField() url = models.URLField(unique=True) def __str__(self): return self.label class Meta: app_label = 'metadata' class Object(models.Model): label = models.TextField() description = models.TextField() # related name should not be objects, because that will cause problems schema = models.ForeignKey( Schema, related_name='objects', on_delete=models.CASCADE) def __str__(self): return "%s.%s" % (self.schema.label, self.label) class Meta: app_label = 'metadata'
ASGI options for django 1.9 and python 2.7
I am currently running django-channels on Daphne and looking for other options. Any and every suggestions are highly appreciated
Django | How to make a reverse Relationship with two models
i want to make a ticket system. I have the main model (TicketSystem) and a model with the messages from the users (TicketSystem_Messages).
In the model "TicketSystem_Messages" is the ForeignKey to the model "TicketSystem".
Here is my code:
class TicketSystem(models.Model): subject = models.CharField(_('Subject'),max_length=30, blank=False, default="N/A") message = models.TextField(_('Message'), null=False, blank=False) created_date = models.DateTimeField(_('Date'), default=datetime.utcnow().replace(tzinfo=utc)) fertig_date = models.DateTimeField(_('Date'), default=datetime.utcnow().replace(tzinfo=utc)) class TicketSystem_Messages(models.Model): user_name = models.ForeignKey(User) status = models.ForeignKey(TicketSystem_Status) ticketid = models.ForeignKey(TicketSystem) message = models.TextField(_('Message'), null=False, blank=False) created_date = models.DateTimeField(_('Sent'), default=datetime.utcnow().replace(tzinfo=utc))
At the moment i get the Tickets without the Messages:
sql_TicketSystem = TicketSystem.objects.filter(id=kwargs['pk'])
I want to make a LEFT JOIN like this
SELECT * FROM TicketSystem LEFT JOIN TicketSystem_Messages ON Ticketsystem.id = TicketSystem_Messages.ticketid
I heard something about "select_related" and "prefetch_related" and tried it but it does not work.
should I create database table for form data?
should I create a database table for form data that is going to be used in the future? Say, I'm going to ask the user to choose their favorite sports among the ones I list for them, now, if I hard-type this data in the view, then I have very little control on them. For example, if in the future, I'm going to make it possible for the admin to list all the registered users who like Basketball/Football/etc, then I have to have the exact same list of sports or else I have to re-type them which seems horrible.
One solution that comes to my mind for using less tables is assigning an unique identifier for each form that has such data and then retrieving the data in case of need. I'm not sure if it works since I've not given it a try yet. Is there a common/better solution for this?
The file "" does not exist
I want to upload a file on jobs request page in my site but after upload file on my page, I'm getting the following error:
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException The file "" does not exist
My code is:
$path = $request->file('image')->store('public'); echo $path;
Form aligning over different columns
I need to make a form page that is divided into two parts: one column with a certain colour on the left and another white column on the right. These two parts are contained in a container class. The form needs to be aligned in a way that the labels are in the coloured column, and the inputs on the right side, in the white column.
The problem appears when I need to align the labels and inputs on either side horizontally. All options I've seen for horizontal aligning call for the labels and inputs to be in the same division or column, but I cannot do this, since I need the design to have the two separate parts and the labels and inputs to align to the dividing line between the two (and scale accordingly).
How could I manage this? Tried using the choice that included the label column (col-sm-4) and input column (col-sm-8), but the labels did not align horizontally with the inputs that way.
A mock-up of what I imagine it to look like. Added random colours for understandability. The pink box is the left column with labels and the white one is the input column. The line where these two boxes/columns meet is the line with which the labels and inputs need to align to, which is why I can't just make the background some colour|white. The alignment is necessary when scaling. Also, the column should need to become vertically aligned when the window is too small (eg a phone screen), so the label one becomes the upper one and input one is down, which is another reason there needs to be some sort of grid/columns.
Sorry, I have code but it doesn't work as needed currently, so I hope the image helps enough.