How to return duplicate records only once and access the attributes of the model in the template ??
I have a model :
class Post(models.Model): title = models.CharField(max_length=20,null=True) author = models.ForeignKey(User,on_delete = models.CASCADE)
What's different in this model is that users can add multiple posts with the same title and I want to use this functionality.
In my home page, I would like to return only the first occurence of the title.
For Example :
There could be 10 posts with the title 'Global Warming is real' but I want to show the title only once on the home page and subsequently add a link to a page which will contain all the posts with the title 'Global Warming is real'.
So Far, I have tried the following :
posts = Post.objects.values('title').distinct() posts
But in the above implementation a dictionary is created with only title present. I want the authors also.
So I did the following (As my database is MySQL so I cannot use distinct('title')):
posts = Post.objects.values('title','author').annotate(counter=Count('title')).filter(counter__gt=1) posts
Here, I can see the author key and I can't seem to figure out how to get the relative user-name through this (I have used the Django User Model) ??
Then I tried the following :
search = list(Post.objects.values('title').annotate(counter=Count('title')).filter(counter__gt=1)) list1 = [] for iter in range(len(search)): list1.append(search[i]['title']) final_posts = Post.objects.filter(title = [item for item in list1])
This returns all the repetitive posts again in final_posts.
I am just stuck here.
Sorry for the long question.
Is there a better way to do this ???
TL;DR : Model containing multiple records with the same title. Want to return only one occurence on home page and also the subsequent author of that post.
submitted by
tejasj777 to
django
Mumble & Murmur (1.2.19) defaulting to TLS 1.0 and I can't force TLS 1.2
Mumble/Murmurd (v1.2.19-lp150.3.3.1) is configured to connect using TLS 1.0 by default. I performed a fresh install of mumble on my desktop as a test to verify, but this is how my other servers behave as well.
Edit: I am running OpenSUSE 15.0 and using openSSL v1.1.0i-lp150.6.1 (1.0.2p-lp150.2.19.1 is also installed)
UDP pings followed by TLS handshake, finally ending with a link established
8 2.050127258 127.0.0.1 127.0.0.1 UDP 66 64738 > 44490 Len=24 9 2.505424206 127.0.0.1 127.0.0.1 TCP 74 35624 > 64738 [SYN] Seq=0 Win=43690 Len=0 MSS=65495 SACK_PERM=1 TSval=2628100678 TSecr=0 WS=128 10 2.505452129 127.0.0.1 127.0.0.1 TCP 74 64738 > 35624 [SYN, ACK] Seq=0 Ack=1 Win=43690 Len=0 MSS=65495 SACK_PERM=1 TSval=2628100678 TSecr=2628100678 WS=128 11 2.505471726 127.0.0.1 127.0.0.1 TCP 66 35624 > 64738 [ACK] Seq=1 Ack=1 Win=43776 Len=0 TSval=2628100678 TSecr=2628100678 12 2.514800479 127.0.0.1 127.0.0.1 TLSv1 156 Client Hello 13 2.514823732 127.0.0.1 127.0.0.1 TCP 66 64738 > 35624 [ACK] Seq=1 Ack=91 Win=43776 Len=0 TSval=2628100688 TSecr=2628100687 14 2.520695461 127.0.0.1 127.0.0.1 TLSv1 1018 Server Hello, Certificate, Certificate Request, Server Hello Done 15 2.520710049 127.0.0.1 127.0.0.1 TCP 66 35624 > 64738 [ACK] Seq=91 Ack=953 Win=45696 Len=0 TSval=2628100693 TSecr=2628100693 16 2.522037402 127.0.0.1 127.0.0.1 TLSv1 1465 Certificate, Client Key Exchange, Certificate Verify, Change Cipher Spec, Encrypted Handshake Message 17 2.522057841 127.0.0.1 127.0.0.1 TCP 66 64738 > 35624 [ACK] Seq=953 Ack=1490 Win=174720 Len=0 TSval=2628100695 TSecr=2628100695 18 2.523969822 127.0.0.1 127.0.0.1 TLSv1 1193 New Session Ticket, Change Cipher Spec, Encrypted Handshake Message, Application Data 19 2.524207629 127.0.0.1 127.0.0.1 TCP 66 35624 > 64738 [FIN, ACK] Seq=1490 Ack=2080 Win=47872 Len=0 TSval=2628100697 TSecr=2628100697 20 2.524233598 127.0.0.1 127.0.0.1 TCP 66 64738 > 35624 [FIN, ACK] Seq=2080 Ack=1491 Win=174720 Len=0 TSval=2628100697 TSecr=2628100697 21 2.52424005 127.0.0.1 127.0.0.1 TCP 66 35624 > 64738 [ACK] Seq=1491 Ack=2081 Win=47872 Len=0 TSval=2628100697 TSecr=2628100697 22 4.55673092 127.0.0.1 127.0.0.1 TCP 74 35626 > 64738 [SYN] Seq=0 Win=43690 Len=0 MSS=65495 SACK_PERM=1 TSval=2628102729 TSecr=0 WS=128 23 4.556757049 127.0.0.1 127.0.0.1 TCP 74 64738 > 35626 [SYN, ACK] Seq=0 Ack=1 Win=43690 Len=0 MSS=65495 SACK_PERM=1 TSval=2628102729 TSecr=2628102729 WS=128 24 4.556774452 127.0.0.1 127.0.0.1 TCP 66 35626 > 64738 [ACK] Seq=1 Ack=1 Win=43776 Len=0 TSval=2628102729 TSecr=2628102729 25 4.562154928 127.0.0.1 127.0.0.1 TCP 156 35626 > 64738 [PSH, ACK] Seq=1 Ack=1 Win=43776 Len=90 TSval=2628102735 TSecr=2628102729 26 4.56217169 127.0.0.1 127.0.0.1 TCP 66 64738 > 35626 [ACK] Seq=1 Ack=91 Win=43776 Len=0 TSval=2628102735 TSecr=2628102735 27 4.579825951 127.0.0.1 127.0.0.1 TCP 1018 64738 > 35626 [PSH, ACK] Seq=1 Ack=91 Win=43776 Len=952 TSval=2628102752 TSecr=2628102735 28 4.57984676 127.0.0.1 127.0.0.1 TCP 66 35626 > 64738 [ACK] Seq=91 Ack=953 Win=45696 Len=0 TSval=2628102753 TSecr=2628102752 29 4.582777065 127.0.0.1 127.0.0.1 TCP 1465 35626 > 64738 [PSH, ACK] Seq=91 Ack=953 Win=45696 Len=1399 TSval=2628102755 TSecr=2628102752 30 4.582838019 127.0.0.1 127.0.0.1 TCP 66 64738 > 35626 [ACK] Seq=953 Ack=1490 Win=174720 Len=0 TSval=2628102756 TSecr=2628102755 31 4.585944034 127.0.0.1 127.0.0.1 TCP 1193 64738 > 35626 [PSH, ACK] Seq=953 Ack=1490 Win=174720 Len=1127 TSval=2628102759 TSecr=2628102755 32 4.586882687 127.0.0.1 127.0.0.1 TCP 187 35626 > 64738 [PSH, ACK] Seq=1490 Ack=2080 Win=47872 Len=121 TSval=2628102760 TSecr=2628102759 33 4.624363349 127.0.0.1 127.0.0.1 TCP 379 64738 > 35626 [PSH, ACK] Seq=2080 Ack=1611 Win=174720 Len=313 TSval=2628102797 TSecr=2628102760 34 4.625155748 127.0.0.1 127.0.0.1 UDP 50 53914 > 64738 Len=8 35 4.625257158 127.0.0.1 127.0.0.1 UDP 50 64738 > 53914 Len=8
Here is the handshake:
TLSv1 Record Layer: Handshake Protocol: Client Hello Content Type: Handshake (22) Version: TLS 1.0 (0x0301) Length: 85 Handshake Protocol: Client Hello
Murmur.ini:
# Murmur configuration file. # # General notes: # * Settings in this file are default settings and many of them can be overridden # with virtual server specific configuration via the Ice or DBus interface. # * Due to the way this configuration file is read some rules have to be # followed when specifying variable values (as in variable = value): # * Make sure to quote the value when using commas in strings or passwords. # NOT variable = super,secret BUT variable = "super,secret" # * Make sure to escape special characters like '\' or '"' correctly # NOT variable = """ BUT variable = "\"" # NOT regex = \w* BUT regex = \\w* # Path to database. If blank, will search for # murmur.sqlite in default locations or create it if not found. database= # If you wish to use something other than SQLite, you'll need to set the name # of the database above, and also uncomment the below. # Sticking with SQLite is strongly recommended, as it's the most well tested # and by far the fastest solution. # #dbDriver=QMYSQL #dbUsername= #dbPassword= #dbHost= #dbPort= #dbPrefix=murmur_ #dbOpts= # Murmur defaults to not using D-Bus. If you wish to use dbus, which is one of the # RPC methods available in Murmur, please specify so here. # dbus=system # Alternate D-Bus service name. Only use if you are running distinct # murmurd processes connected to the same D-Bus daemon. #dbusservice=net.sourceforge.mumble.murmur # If you want to use ZeroC Ice to communicate with Murmur, you need # to specify the endpoint to use. Since there is no authentication # with ICE, you should only use it if you trust all the users who have # shell access to your machine. # Please see the ICE documentation on how to specify endpoints. #ice="tcp -h 127.0.0.1 -p 6502" # Ice primarily uses local sockets. This means anyone who has a # user account on your machine can connect to the Ice services. # You can set a plaintext "secret" on the Ice connection, and # any script attempting to access must then have this secret # (as context with name "secret"). # Access is split in read (look only) and write (modify) # operations. Write access always includes read access, # unless read is explicitly denied (see note below). # # Note that if this is uncommented and with empty content, # access will be denied. #icesecretread= icesecretwrite= # How many login attempts do we tolerate from one IP # inside a given timeframe before we ban the connection? # Note that this is global (shared between all virtual servers), and that # it counts both successfull and unsuccessfull connection attempts. # Set either Attempts or Timeframe to 0 to disable. #autobanAttempts = 10 #autobanTimeframe = 120 #autobanTime = 300 # Specifies the file Murmur should log to. By default, Murmur # logs to the file 'murmur.log'. If you leave this field blank # on Unix-like systems, Murmur will force itself into foreground # mode which logs to the console. logfile=/valog/mumble-servemurmur.log # If set, Murmur will write its process ID to this file # when running in daemon mode (when the -fg flag is not # specified on the command line). Only available on # Unix-like systems. pidfile=/varun/mumble-servemumble-server.pid # The below will be used as defaults for new configured servers. # If you're just running one server (the default), it's easier to # configure it here than through D-Bus or Ice. # # Welcome message sent to clients when they connect. welcometext="
Welcome to this server running Murmur.
Enjoy your stay!
" # Port to bind TCP and UDP sockets to. port=64738 # Specific IP or hostname to bind to. # If this is left blank (default), Murmur will bind to all available addresses. #host= # Password to join server. serverpassword= # Maximum bandwidth (in bits per second) clients are allowed # to send speech at. bandwidth=72000 # Maximum number of concurrent clients allowed. users=100 # Amount of users with Opus support needed to force Opus usage, in percent. # 0 = Always enable Opus, 100 = enable Opus if it's supported by all clients. #opusthreshold=100 # Maximum depth of channel nesting. Note that some databases like MySQL using # InnoDB will fail when operating on deeply nested channels. #channelnestinglimit=10 # Regular expression used to validate channel names. # (Note that you have to escape backslashes with \ ) #channelname=[ \\-=\\w\\#\\[\\]\\{\\}\\(\\)\\@\\|]+ # Regular expression used to validate user names. # (Note that you have to escape backslashes with \ ) #username=[-=\\w\\[\\]\\{\\}\\(\\)\\@\\|\\.]+ # Maximum length of text messages in characters. 0 for no limit. #textmessagelength=5000 # Maximum length of text messages in characters, with image data. 0 for no limit. #imagemessagelength=131072 # Allow clients to use HTML in messages, user comments and channel descriptions? #allowhtml=true # Murmur retains the per-server log entries in an internal database which # allows it to be accessed over D-Bus/ICE. # How many days should such entries be kept? # Set to 0 to keep forever, or -1 to disable logging to the DB. #logdays=31 # To enable public server registration, the serverpassword must be blank, and # this must all be filled out. # The password here is used to create a registry for the server name; subsequent # updates will need the same password. Don't lose your password. # The URL is your own website, and only set the registerHostname for static IP # addresses. # Only uncomment the 'registerName' parameter if you wish to give your "Root" channel a custom name. # #registerName=Mumble Server #registerPassword=secret #registerUrl=https://www.mumble.info/ #registerHostname= # If this option is enabled, the server will announce its presence via the # bonjour service discovery protocol. To change the name announced by bonjour # adjust the registerName variable. # See http://developer.apple.com/networking/bonjouindex.html for more information # about bonjour. #bonjour=True # If you have a proper SSL certificate, you can provide the filenames here. # Otherwise, Murmur will create it's own certificate automatically. #sslCert= #sslKey= # The sslCiphers option chooses the cipher suites to make available for use # in SSL/TLS. This option is server-wide, and cannot be set on a # per-virtual-server basis. # # This option is specified using OpenSSL cipher list notation (see # https://www.openssl.org/docs/apps/ciphers.html#CIPHER-LIST-FORMAT). # # It is recommended that you try your cipher string using 'openssl ciphers ' # before setting it here, to get a feel for which cipher suites you will get. # # After setting this option, it is recommend that you inspect your Murmur log # to ensure that Murmur is using the cipher suites that you expected it to. # # Note: Changing this option may impact the backwards compatibility of your # Murmur server, and can remove the ability for older Mumble clients to be able # to connect to it. #sslCiphers=EECDH+AESGCM:AES256-SHA:AES128-SHA # If Murmur is started as root, which user should it switch to? # This option is ignored if Murmur isn't started with root privileges. uname=mumble-server # If this options is enabled, only clients which have a certificate are allowed # to connect. #certrequired=False # If enabled, clients are sent information about the servers version and operating # system. #sendversion=True # You can configure any of the configuration options for Ice here. We recommend # leave the defaults as they are. # Please note that this section has to be last in the configuration file. # [Ice] Ice.Warn.UnknownProperties=1 Ice.MessageSizeMax=65536
Does anyone have any ideas why this is the case or how to fix it?
submitted by
zasx20 to
mumble